<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.5">
<meta name="author" content="2019-08-08 13:15:33 CEST">
<title>N4JS Language Specification</title>
<link rel="stylesheet" href="styles/spec.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<!-- ************* docinfo ******************************************************************* -->


<!-- ************* Favicon ************-->
<link rel="icon" href="images/favicon.ico" />

<!-- ************* Back-to-top JQuery ************* -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>


<link href="styles/prism.min.css" rel="stylesheet" />
<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

<!-- ************* Styles ************* -->
<link rel="stylesheet" type="text/css" href="styles/n4jsspec-adoc.css">


<!-- ****************** NavBar ****************** -->
<div id="menubar">
	<div class="banner">
        <a href="https://www.eclipse.org/n4js/#"><img id="logo" src="images/n4js-logo.png" alt="Eclipse N4JS"></a>
    </div>
<ul>
  <li><a href="index.html">Index</a></li>
</ul>
</div>
<!-- ************* docinfo ******************************************************************* -->
<style>
      .admonitionblock td.icon .icon-todo:before{content:"\f249";color:#f4ee42}
    </style>
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>N4JS Language Specification</h1>
<div class="details">
<span id="author" class="author">2019-08-08 13:15:33 CEST</span><br>
<span id="revnumber">version 0.9</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="introduction.html#_introduction">1. Introduction</a>
<ul class="sectlevel2">
<li><a href="introduction.html#_notation">1.1. Notation</a>
<ul class="sectlevel3">
<li><a href="introduction.html#_grammar-notation">1.1.1. Grammar Notation</a></li>
<li><a href="introduction.html#_type-judgments-and-rules-and-constraints-notation">1.1.2. Type Judgments and Rules and Constraints Notation</a>
<ul class="sectlevel4">
<li><a href="introduction.html#_typing-rules-and-judgments">1.1.2.1. Typing Rules and Judgments</a></li>
<li><a href="introduction.html#_types-of-an-element">1.1.2.2. Types of an Element</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="introduction.html#_auxiliary-functions">1.2. Auxiliary Functions</a>
<ul class="sectlevel3">
<li><a href="introduction.html#_binding">1.2.1. Binding</a></li>
<li><a href="introduction.html#_merging-types">1.2.2. Merging Types</a>
<ul class="sectlevel4">
<li><a href="introduction.html#_logic-formulas">1.2.2.1. Logic Formulas</a></li>
</ul>
</li>
<li><a href="introduction.html#_symbols-and-font-convention">1.2.3. Symbols and Font Convention</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="grammar.html#_grammar">2. Grammar</a>
<ul class="sectlevel2">
<li><a href="grammar.html#_lexical-conventions">2.1. Lexical Conventions</a>
<ul class="sectlevel3">
<li><a href="grammar.html#_identifier-names-and-identifiers">2.1.1. Identifier Names and Identifiers</a></li>
<li><a href="grammar.html#_this-keyword">2.1.2. This Keyword</a></li>
<li><a href="grammar.html#_regular-expression-literals">2.1.3. Regular Expression Literals</a></li>
<li><a href="grammar.html#_automatic-semicolon-insertion">2.1.4. Automatic Semicolon Insertion</a></li>
<li><a href="grammar.html#_jsdoc">2.1.5. JSDoc</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="names.html#_names">3. Names</a>
<ul class="sectlevel2">
<li><a href="names.html#_access-control">3.1. Access Control</a></li>
<li><a href="names.html#_accessibility-of-types-top-level-variables-and-function-declarations">3.2. Accessibility of Types, Top-Level Variables and Function Declarations</a>
<ul class="sectlevel3">
<li><a href="names.html#_accessibility-of-members">3.2.1. Accessibility of Members</a></li>
<li><a href="names.html#_valid-names">3.2.2. Valid Names</a></li>
<li><a href="names.html#_qualified-names">3.2.3. Qualified Names</a></li>
<li><a href="names.html#_name-duplicates">3.2.4. Name Duplicates</a>
<ul class="sectlevel4">
<li><a href="names.html#_lexical-environment">3.2.4.1. Lexical Environment</a></li>
<li><a href="names.html#_duplicates-and-shadowing">3.2.4.2. Duplicates and Shadowing</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_types">4. Types</a>
<ul class="sectlevel2">
<li><a href="#_overview">4.1. Overview</a></li>
<li><a href="#_type-expressions">4.2. Type Expressions</a>
<ul class="sectlevel3">
<li><a href="#_syntax">4.2.1. Syntax</a></li>
<li><a href="#_properties">4.2.2. Properties</a></li>
<li><a href="#_semantics">4.2.3. Semantics</a></li>
</ul>
</li>
<li><a href="#_type-inference">4.3. Type Inference</a></li>
<li><a href="#_generic-and-parameterized-types">4.4. Generic and Parameterized Types</a>
<ul class="sectlevel3">
<li><a href="#_generic-types">4.4.1. Generic Types</a></li>
<li><a href="#_type-variables">4.4.2. Type Variables</a></li>
<li><a href="#_parameterized-types">4.4.3. Parameterized Types</a></li>
</ul>
</li>
<li><a href="#_primitive-ecmascript-types">4.5. Primitive ECMAScript Types</a>
<ul class="sectlevel3">
<li><a href="#_undefined-type">4.5.1. Undefined Type</a></li>
<li><a href="#_null-type">4.5.2. Null Type</a></li>
<li><a href="#_primitive-boolean-type">4.5.3. Primitive Boolean Type</a></li>
<li><a href="#_primitive-string-type">4.5.4. Primitive String Type</a></li>
<li><a href="#_primitive-number-type">4.5.5. Primitive Number Type</a></li>
<li><a href="#_primitive-type-int">4.5.6. Primitive Type int</a></li>
<li><a href="#_primitive-symbol-type">4.5.7. Primitive Symbol Type</a></li>
</ul>
</li>
<li><a href="#_primitive-n4js-types">4.6. Primitive N4JS Types</a>
<ul class="sectlevel3">
<li><a href="#_any-type">4.6.1. Any Type</a>
<ul class="sectlevel4">
<li><a href="#any-type-semantics">4.6.1.1. Semantics</a></li>
<li><a href="#any-type-type-inference">4.6.1.2. Type Inference</a>
<ul class="sectlevel5">
<li><a href="#_default-type-of-variables">4.6.1.2.1. Default Type of Variables</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_void-type">4.6.2. Void Type</a>
<ul class="sectlevel4">
<li><a href="#void-type-semantics">4.6.2.1. Semantics</a></li>
</ul>
</li>
<li><a href="#_unknown-type">4.6.3. Unknown Type</a></li>
<li><a href="#_primitive-pathselector-and-i18nkey">4.6.4. Primitive Pathselector and I18nKey</a>
<ul class="sectlevel4">
<li><a href="#pathselector-semantics">4.6.4.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_built-in-ecmascript-object-types">4.7. Built-in ECMAScript Object Types</a>
<ul class="sectlevel3">
<li><a href="#ECMAScript-objects-semantics">4.7.1. Semantics</a></li>
<li><a href="#_object-type">4.7.2. Object Type</a></li>
<li><a href="#_function-object-type">4.7.3. Function-Object-Type</a></li>
<li><a href="#_array-object-type">4.7.4. Array Object Type</a></li>
<li><a href="#_string-object-type">4.7.5. String Object Type</a></li>
<li><a href="#_boolean-object-type">4.7.6. Boolean Object Type</a></li>
<li><a href="#_number-object-type">4.7.7. Number Object Type</a></li>
<li><a href="#_global-object-type">4.7.8. Global Object Type</a></li>
<li><a href="#_symbol">4.7.9. Symbol</a></li>
<li><a href="#_promise">4.7.10. Promise</a></li>
<li><a href="#_iterator-interface">4.7.11. Iterator Interface</a></li>
<li><a href="#_iterable-interface">4.7.12. Iterable Interface</a></li>
</ul>
</li>
<li><a href="#_built-in-n4js-types">4.8. Built-In N4JS Types</a>
<ul class="sectlevel3">
<li><a href="#_n4object">4.8.1. N4Object</a>
<ul class="sectlevel4">
<li><a href="#N4Object-semantics">4.8.1.1. Semantics</a></li>
</ul>
</li>
<li><a href="#_n4class">4.8.2. N4Class</a></li>
<li><a href="#IterableN">4.8.3. IterableN</a></li>
</ul>
</li>
<li><a href="#_type-modifiers">4.9. Type Modifiers</a>
<ul class="sectlevel3">
<li><a href="#Type_Modifiers_Dynamic">4.9.1. Dynamic</a></li>
<li><a href="#_optional-return-types">4.9.2. Optional Return Types</a></li>
</ul>
</li>
<li><a href="#_union-and-intersection-type-composed-types">4.10. Union and Intersection Type (Composed Types)</a>
<ul class="sectlevel3">
<li><a href="#_union-type">4.10.1. Union Type</a>
<ul class="sectlevel4">
<li><a href="#union-type-syntax">4.10.1.1. Syntax</a></li>
<li><a href="#union-type-semantics">4.10.1.2. Semantics</a></li>
<li><a href="#_warnings">4.10.1.3. Warnings</a></li>
</ul>
</li>
<li><a href="#_intersection-type">4.10.2. Intersection Type</a>
<ul class="sectlevel4">
<li><a href="#intersection-type-syntax">4.10.2.1. Syntax</a></li>
<li><a href="#intersection-type-semantics">4.10.2.2. Semantics</a></li>
<li><a href="#_warnings-2">4.10.2.3. Warnings</a></li>
</ul>
</li>
<li><a href="#_composed-types-in-wildcards">4.10.3. Composed Types in Wildcards</a></li>
<li><a href="#_property-access-for-composed-types">4.10.4. Property Access for Composed Types</a>
<ul class="sectlevel4">
<li><a href="#_properties-of-union-type">4.10.4.1. Properties of Union Type</a>
<ul class="sectlevel5">
<li><a href="#_remarks-on-union-type-s-members">4.10.4.1.1. Remarks on union type’s members:</a></li>
</ul>
</li>
<li><a href="#_properties-of-intersection-type">4.10.4.2. Properties of Intersection Type</a>
<ul class="sectlevel5">
<li><a href="#_remarks-on-intersection-type-s-methods">4.10.4.2.1. Remarks on intersection type’s methods:</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_constructor-and-classifier-type">4.11. Constructor and Classifier Type</a>
<ul class="sectlevel3">
<li><a href="#_syntax-3">4.11.1. Syntax</a></li>
<li><a href="#_semantics-2">4.11.2. Semantics</a></li>
<li><a href="#_constructors-and-prototypes-in-ecmascript-2015">4.11.3. Constructors and Prototypes in ECMAScript 2015</a></li>
</ul>
</li>
<li><a href="#_this-type">4.12. This Type</a>
<ul class="sectlevel3">
<li><a href="#this-type-syntax">4.12.1. Syntax</a></li>
<li><a href="#this-keyword-semantics">4.12.2. Semantics</a></li>
</ul>
</li>
<li><a href="#_enums">4.13. Enums</a>
<ul class="sectlevel3">
<li><a href="#_enums-n4js">4.13.1. Enums (N4JS)</a>
<ul class="sectlevel4">
<li><a href="#enums-syntax">4.13.1.1. Syntax</a></li>
<li><a href="#enums-semantics">4.13.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="#_string-based-enums">4.13.2. String-Based Enums</a></li>
</ul>
</li>
<li><a href="#_short-hand-syntax">4.14. Short-Hand Syntax</a>
<ul class="sectlevel3">
<li><a href="#_array-short-hand-syntax">4.14.1. Array Short-Hand Syntax</a></li>
<li><a href="#_iterablen-short-hand-syntax">4.14.2. IterableN Short-Hand Syntax</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_classifiers">5. Classifiers</a>
<ul class="sectlevel2">
<li><a href="classifiers.html#_n4js-specific-classifiers">5.1. N4JS Specific Classifiers</a>
<ul class="sectlevel3">
<li><a href="classifiers.html#_properties-2">5.1.1. Properties</a></li>
<li><a href="classifiers.html#_common-semantics-of-classifiers">5.1.2. Common Semantics of Classifiers</a></li>
<li><a href="classifiers.html#_classes">5.1.3. Classes</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_definition-of-classes">5.1.3.1. Definition of Classes</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#class-syntax">5.1.3.1.1. Syntax</a></li>
<li><a href="classifiers.html#class-properties">5.1.3.1.2. Properties</a></li>
<li><a href="classifiers.html#class-type-inference">5.1.3.1.3. Type Inference</a></li>
</ul>
</li>
<li><a href="classifiers.html#class-semantics">5.1.3.2. Semantics</a></li>
<li><a href="classifiers.html#_final-modifier">5.1.3.3. Final Modifier</a></li>
<li><a href="classifiers.html#_abstract-classes">5.1.3.4. Abstract Classes</a></li>
<li><a href="classifiers.html#_non-instantiable-classes">5.1.3.5. Non-Instantiable Classes</a></li>
<li><a href="classifiers.html#_superclass">5.1.3.6. Superclass</a></li>
</ul>
</li>
<li><a href="classifiers.html#_interfaces">5.1.4. Interfaces</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_definition-of-interfaces">5.1.4.1. Definition of Interfaces</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#interfaces-syntax">5.1.4.1.1. Syntax</a></li>
<li><a href="classifiers.html#interfaces-properties">5.1.4.1.2. Properties</a></li>
<li><a href="classifiers.html#interfaces-type-inference">5.1.4.1.3. Type Inference</a></li>
<li><a href="classifiers.html#interfaces-semantics">5.1.4.1.4. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_generic-classifiers">5.1.5. Generic Classifiers</a></li>
<li><a href="classifiers.html#sec:definition-site-variance">5.1.6. Definition-Site Variance</a></li>
</ul>
</li>
<li><a href="classifiers.html#_members">5.2. Members</a>
<ul class="sectlevel3">
<li><a href="classifiers.html#_syntax-4">5.2.1. Syntax</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_properties-3">5.2.1.1. Properties</a></li>
</ul>
</li>
<li><a href="classifiers.html#_semantics-3">5.2.2. Semantics</a></li>
<li><a href="classifiers.html#_methods">5.2.3. Methods</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_syntax-5">5.2.3.1. Syntax</a></li>
<li><a href="classifiers.html#_properties-4">5.2.3.2. Properties</a></li>
<li><a href="classifiers.html#_semantics-4">5.2.3.3. Semantics</a></li>
<li><a href="classifiers.html#_final-methods">5.2.3.4. Final Methods</a></li>
<li><a href="classifiers.html#_abstract-methods">5.2.3.5. Abstract Methods</a></li>
<li><a href="classifiers.html#_generic-methods">5.2.3.6. Generic Methods</a></li>
</ul>
</li>
<li><a href="classifiers.html#_default-methods-in-interfaces">5.2.4. Default Methods in Interfaces</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_asynchronous-methods">5.2.4.1. Asynchronous Methods</a></li>
</ul>
</li>
<li><a href="classifiers.html#_constructors">5.2.5. Constructors</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_structural-this-type-in-constructor">5.2.5.1. Structural This Type in Constructor</a></li>
<li><a href="classifiers.html#spec-constructor">5.2.5.2. @Spec Constructor</a></li>
<li><a href="classifiers.html#_callable-constructors">5.2.5.3. Callable Constructors</a></li>
<li><a href="classifiers.html#_covariant-constructors">5.2.5.4. Covariant Constructors</a></li>
</ul>
</li>
<li><a href="classifiers.html#_data-fields">5.2.6. Data Fields</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#data-fields-syntax">5.2.6.1. Syntax</a></li>
<li><a href="classifiers.html#data-fields-properties">5.2.6.2. Properties</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#data-fields-semantics">5.2.6.2.1. Semantics</a></li>
<li><a href="classifiers.html#data-fields-type-inference">5.2.6.2.2. Type Inference</a></li>
</ul>
</li>
<li><a href="classifiers.html#_assignment-modifiers">5.2.6.3. Assignment Modifiers</a></li>
<li><a href="classifiers.html#_field-accessors-getter-setter">5.2.6.4. Field Accessors (Getter/Setter)</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#field-acessors-syntax">5.2.6.4.1. Syntax</a></li>
<li><a href="classifiers.html#field-acessors-properties">5.2.6.4.2. Properties</a></li>
<li><a href="classifiers.html#field-accessors-semantics">5.2.6.4.3. Semantics</a></li>
</ul>
</li>
<li><a href="classifiers.html#optional-fields">5.2.6.5. Optional Fields</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#_syntax-6">5.2.6.5.1. Syntax</a></li>
<li><a href="classifiers.html#_semantics-5">5.2.6.5.2. Semantics</a></li>
<li><a href="classifiers.html#_background">5.2.6.5.3. Background</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_static-members">5.2.7. Static Members</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_access-from-and-to-static-members">5.2.7.1. Access From and To Static Members</a></li>
<li><a href="classifiers.html#_generic-static-methods">5.2.7.2. Generic static methods</a></li>
<li><a href="classifiers.html#_static-members-of-interfaces">5.2.7.3. Static Members of Interfaces</a></li>
</ul>
</li>
<li><a href="classifiers.html#_redefinition-of-members">5.2.8. Redefinition of Members</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_overriding-of-members">5.2.8.1. Overriding of Members</a></li>
<li><a href="classifiers.html#_implementation-of-members">5.2.8.2. Implementation of Members</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#_member-consumption">5.2.8.2.1. Member Consumption</a></li>
<li><a href="classifiers.html#_member-implementation">5.2.8.2.2. Member Implementation</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="classifiers.html#_structural-typing">5.3. Structural Typing</a>
<ul class="sectlevel3">
<li><a href="classifiers.html#_syntax-7">5.3.1. Syntax</a></li>
<li><a href="classifiers.html#_definition-site-structural-typing">5.3.2. Definition Site Structural Typing</a></li>
<li><a href="classifiers.html#_use-site-structural-typing">5.3.3. Use-Site Structural Typing</a></li>
<li><a href="classifiers.html#structural-readWriteInit-field-typing">5.3.4. Structural Read-only, Write-only and Initializer Field Typing</a></li>
<li><a href="classifiers.html#_public-setter-annotated-with-code-providesinitializer-code">5.3.5. Public Setter Annotated With <code>ProvidesInitializer</code></a></li>
<li><a href="classifiers.html#_structural-types-with-optional-fields">5.3.6. Structural Types With Optional Fields</a></li>
<li><a href="classifiers.html#_structural-types-with-access-modifier">5.3.7. Structural Types With Access Modifier</a></li>
<li><a href="classifiers.html#_structural-types-with-additional-members">5.3.8. Structural Types With Additional Members</a>
<ul class="sectlevel4">
<li><a href="classifiers.html#_syntax-8">5.3.8.1. Syntax</a>
<ul class="sectlevel5">
<li><a href="classifiers.html#_semantics-6">5.3.8.1.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_functions">6. Functions</a>
<ul class="sectlevel2">
<li><a href="functions.html#_function-type">6.1. Function Type</a>
<ul class="sectlevel3">
<li><a href="functions.html#_properties-5">6.1.1. Properties</a></li>
<li><a href="functions.html#function-type-inference">6.1.2. Type Inference</a></li>
<li><a href="functions.html#_autoboxing-of-function-type">6.1.3. Autoboxing of Function Type</a></li>
<li><a href="functions.html#_arguments-object">6.1.4. Arguments Object</a></li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-5-function-definition">6.2. ECMAScript 5 Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_function-declaration">6.2.1. Function Declaration</a>
<ul class="sectlevel4">
<li><a href="functions.html#_syntax-9">6.2.1.1. Syntax</a></li>
<li><a href="functions.html#_semantics-8">6.2.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="functions.html#_function-expression">6.2.2. Function Expression</a>
<ul class="sectlevel4">
<li><a href="functions.html#function-expression-syntax">6.2.2.1. Syntax</a></li>
<li><a href="functions.html#_semantics-and-type-inference">6.2.2.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-2015-function-definition">6.3. ECMAScript 2015 Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_formal-parameters">6.3.1. Formal Parameters</a>
<ul class="sectlevel4">
<li><a href="functions.html#Type_Modifiers_Optional">6.3.1.1. Optional Parameters</a></li>
<li><a href="functions.html#Type_Modifiers_Default">6.3.1.2. Default Parameters</a></li>
<li><a href="functions.html#Type_Modifiers_Variadic">6.3.1.3. Variadic</a></li>
</ul>
</li>
<li><a href="functions.html#_generator-functions">6.3.2. Generator Functions</a>
<ul class="sectlevel4">
<li><a href="functions.html#generator-functions-syntax">6.3.2.1. Syntax</a></li>
<li><a href="functions.html#generator-functions-semantics">6.3.2.2. Semantics</a></li>
<li><a href="functions.html#_generator-arrow-functions">6.3.2.3. Generator Arrow Functions</a></li>
</ul>
</li>
<li><a href="functions.html#_arrow-function-expression">6.3.3. Arrow Function Expression</a>
<ul class="sectlevel4">
<li><a href="functions.html#arrow-function-expression-syntax">6.3.3.1. Syntax</a></li>
<li><a href="functions.html#arrow-function-expression-semantics-and-type-inference">6.3.3.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_ecmascript-proposals-function-definition">6.4. ECMAScript Proposals Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_asynchronous-functions">6.4.1. Asynchronous Functions</a>
<ul class="sectlevel4">
<li><a href="functions.html#asynchronous-functions-syntax">6.4.1.1. Syntax</a></li>
<li><a href="functions.html#asynchronous-functions-semantics">6.4.1.2. Semantics</a></li>
<li><a href="functions.html#_asynchronous-arrow-functions">6.4.1.3. Asynchronous Arrow Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="functions.html#_n4js-extended-function-definition">6.5. N4JS Extended Function Definition</a>
<ul class="sectlevel3">
<li><a href="functions.html#_generic-functions">6.5.1. Generic Functions</a></li>
<li><a href="functions.html#_promisifiable-functions">6.5.2. Promisifiable Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_conversions-and-reflection">7. Conversions and Reflection</a>
<ul class="sectlevel2">
<li><a href="conversions_and_reflection.html#_autoboxing-and-coercing">7.1. Autoboxing and Coercing</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_coercing">7.1.1. Coercing</a></li>
<li><a href="conversions_and_reflection.html#_autoboxing-of-primitives">7.1.2. Autoboxing of Primitives</a></li>
<li><a href="conversions_and_reflection.html#_autoboxing-of-function-expressions-and-declarations">7.1.3. Autoboxing of Function Expressions and Declarations</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_auto-conversion-of-objects">7.2. Auto-Conversion of Objects</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_auto-conversion-of-class-instances">7.2.1. Auto-Conversion of Class Instances</a>
<ul class="sectlevel4">
<li><a href="conversions_and_reflection.html#_auto-conversion-of-interface-instances">7.2.1.1. Auto-Conversion of Interface Instances</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_auto-conversion-of-enum-literals">7.2.2. Auto-Conversion of Enum Literals</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_type-cast-and-type-check">7.3. Type Cast and Type Check</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_type-cast">7.3.1. Type Cast</a></li>
<li><a href="conversions_and_reflection.html#_type-check">7.3.2. Type Check</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_reflection-meta-information">7.4. Reflection meta-information</a>
<ul class="sectlevel3">
<li><a href="conversions_and_reflection.html#_reflection-for-classes">7.4.1. Reflection for Classes</a></li>
<li><a href="conversions_and_reflection.html#_reflection-for-interfaces">7.4.2. Reflection for Interfaces</a></li>
<li><a href="conversions_and_reflection.html#_reflection-for-enumerations">7.4.3. Reflection for Enumerations</a></li>
</ul>
</li>
<li><a href="conversions_and_reflection.html#_conversion-of-primitive-types">7.5. Conversion of primitive types</a></li>
</ul>
</li>
<li><a href="expressions.html#_expressions">8. Expressions</a>
<ul class="sectlevel2">
<li><a href="expressions.html#_ecmascript-5-expressions">8.1. ECMAScript 5 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_the-this-literal">8.1.1. The this Literal</a></li>
<li><a href="expressions.html#_identifier">8.1.2. Identifier</a></li>
<li><a href="expressions.html#_literals">8.1.3. Literals</a>
<ul class="sectlevel4">
<li><a href="expressions.html#_integer-literals">8.1.3.1. Integer Literals</a></li>
</ul>
</li>
<li><a href="expressions.html#_array-literal">8.1.4. Array Literal</a></li>
<li><a href="expressions.html#_object-literal">8.1.5. Object Literal</a>
<ul class="sectlevel4">
<li><a href="expressions.html#_properties-6">8.1.5.1. Properties</a></li>
<li><a href="expressions.html#_scoping-and-linking">8.1.5.2. Scoping and linking</a></li>
</ul>
</li>
<li><a href="expressions.html#_parenthesized-expression-and-grouping-operator">8.1.6. Parenthesized Expression and Grouping Operator</a></li>
<li><a href="expressions.html#_property-accessors">8.1.7. Property Accessors</a>
<ul class="sectlevel4">
<li><a href="expressions.html#properties-1">8.1.7.1. Properties</a></li>
</ul>
</li>
<li><a href="expressions.html#_new-expression">8.1.8. New Expression</a></li>
<li><a href="expressions.html#_function-expression-2">8.1.9. Function Expression</a></li>
<li><a href="expressions.html#_function-calls">8.1.10. Function Calls</a></li>
<li><a href="expressions.html#_postfix-expression">8.1.11. Postfix Expression</a></li>
<li><a href="expressions.html#_unary-expression">8.1.12. Unary Expression</a></li>
<li><a href="expressions.html#_multiplicative-expression">8.1.13. Multiplicative Expression</a></li>
<li><a href="expressions.html#_additive-expression">8.1.14. Additive Expression</a>
<ul class="sectlevel4">
<li><a href="expressions.html#type-inference-10">8.1.14.1. Type Inference</a></li>
</ul>
</li>
<li><a href="expressions.html#_bitwise-shift-expression">8.1.15. Bitwise Shift Expression</a></li>
<li><a href="expressions.html#_relational-expression">8.1.16. Relational Expression</a></li>
<li><a href="expressions.html#_equality-expression">8.1.17. Equality Expression</a></li>
<li><a href="expressions.html#_binary-bitwise-expression">8.1.18. Binary Bitwise Expression</a></li>
<li><a href="expressions.html#_binary-logical-expression">8.1.19. Binary Logical Expression</a></li>
<li><a href="expressions.html#_conditional-expression">8.1.20. Conditional Expression</a></li>
<li><a href="expressions.html#_assignment-expression">8.1.21. Assignment Expression</a></li>
<li><a href="expressions.html#_comma-expression">8.1.22. Comma Expression</a></li>
</ul>
</li>
<li><a href="expressions.html#_ecmascript-6-expressions">8.2. ECMAScript 6 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_the-super-keyword">8.2.1. The super Keyword</a></li>
</ul>
</li>
<li><a href="expressions.html#_ecmascript-7-expressions">8.3. ECMAScript 7 Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_await-expression">8.3.1. Await Expression</a></li>
</ul>
</li>
<li><a href="expressions.html#_n4js-specific-expressions">8.4. N4JS Specific Expressions</a>
<ul class="sectlevel3">
<li><a href="expressions.html#_class-expression">8.4.1. Class Expression</a></li>
<li><a href="expressions.html#_cast-as-expression">8.4.2. Cast (As) Expression</a>
<ul class="sectlevel4">
<li><a href="expressions.html#cast-as-expression-semantics-type-inference">8.4.2.1. Semantics and Type Inference</a></li>
</ul>
</li>
<li><a href="expressions.html#Import_Calls">8.4.3. Import Calls</a></li>
</ul>
</li>
<li><a href="expressions.html#compile-time-expressions">8.5. Compile-Time Expressions</a></li>
</ul>
</li>
<li><a href="statements.html#_statements">9. Statements</a>
<ul class="sectlevel2">
<li><a href="statements.html#_ecmascript-5-statements">9.1. ECMAScript 5 Statements</a>
<ul class="sectlevel3">
<li><a href="statements.html#_function-or-field-accessor-bodies">9.1.1. Function or Field Accessor Bodies</a></li>
<li><a href="statements.html#_variable-statement">9.1.2. Variable Statement</a></li>
<li><a href="statements.html#_if-statement">9.1.3. If Statement</a></li>
<li><a href="statements.html#_iteration-statements">9.1.4. Iteration Statements</a></li>
<li><a href="statements.html#_return-statement">9.1.5. Return Statement</a></li>
<li><a href="statements.html#_with-statement">9.1.6. With Statement</a></li>
<li><a href="statements.html#_switch-statement">9.1.7. Switch Statement</a></li>
<li><a href="statements.html#_throw-try-and-catch-statements">9.1.8. Throw, Try, and Catch Statements</a></li>
<li><a href="statements.html#_debugger-statement">9.1.9. Debugger Statement</a></li>
</ul>
</li>
<li><a href="statements.html#_ecmascript-6-statements">9.2. ECMAScript 6 Statements</a>
<ul class="sectlevel3">
<li><a href="statements.html#_let">9.2.1. Let</a></li>
<li><a href="statements.html#_const">9.2.2. Const</a></li>
<li><a href="statements.html#_for-of-statement">9.2.3. <code>for &#8230;&#8203; of</code> statement</a></li>
<li><a href="statements.html#_import-statement">9.2.4. Import Statement</a>
<ul class="sectlevel4">
<li><a href="statements.html#Dynamic_Imports">9.2.4.1. Dynamic Imports</a></li>
<li><a href="statements.html#_immutabilaty-of-imports">9.2.4.2. Immutabilaty of Imports</a></li>
</ul>
</li>
<li><a href="statements.html#_export-statement">9.2.5. Export Statement</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="annotations.html#_annotations">10. Annotations</a>
<ul class="sectlevel2">
<li><a href="annotations.html#_introduction-2">10.1. Introduction</a>
<ul class="sectlevel3">
<li><a href="annotations.html#_syntax-13">10.1.1. Syntax</a></li>
<li><a href="annotations.html#_properties-7">10.1.2. Properties</a></li>
<li><a href="annotations.html#_element-specific-annotations">10.1.3. Element-Specific Annotations</a></li>
<li><a href="annotations.html#_general-annotations">10.1.4. General Annotations</a>
<ul class="sectlevel4">
<li><a href="annotations.html#_idebug">10.1.4.1. IDEBUG</a></li>
</ul>
</li>
<li><a href="annotations.html#idebug-syntax">10.1.5. Syntax</a>
<ul class="sectlevel4">
<li><a href="annotations.html#_semantics-11">10.1.5.1. Semantics</a></li>
<li><a href="annotations.html#_suppress-warnings">10.1.5.2. Suppress Warnings</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="annotations.html#_declaration-of-annotations">10.2. Declaration of Annotations</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_extended-fetaures">11. Extended Fetaures</a>
<ul class="sectlevel2">
<li><a href="extended_fetaures.html#_array-and-object-destructuring">11.1. Array and Object Destructuring</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_syntax-14">11.1.1. Syntax</a></li>
<li><a href="extended_fetaures.html#_semantics-12">11.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_dependency-injection">11.2. Dependency Injection</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_di-components-and-injectors">11.2.1. DI Components and Injectors</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_dicomponent-relations">11.2.1.1. DIComponent Relations</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_binders-and-bindings">11.2.2. Binders and Bindings</a></li>
<li><a href="extended_fetaures.html#_injection-points">11.2.3. Injection Points</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_field-injection">11.2.3.1. Field Injection</a></li>
<li><a href="extended_fetaures.html#_constructor-injection">11.2.3.2. Constructor Injection</a></li>
<li><a href="extended_fetaures.html#_method-injection">11.2.3.3. Method Injection</a>
<ul class="sectlevel5">
<li><a href="extended_fetaures.html#_provider">11.2.3.3.1. Provider</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="extended_fetaures.html#_n4js-di-life-cycle-and-scopes">11.2.4. N4JS DI Life Cycle and Scopes</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_injection-cylces">11.2.4.1. Injection Cylces</a></li>
<li><a href="extended_fetaures.html#_default-scope">11.2.4.2. Default Scope</a></li>
<li><a href="extended_fetaures.html#_singleton-scope">11.2.4.3. Singleton Scope</a></li>
<li><a href="extended_fetaures.html#_per-injection-chain-singleton">11.2.4.4. Per Injection Chain Singleton</a></li>
</ul>
</li>
<li><a href="extended_fetaures.html#_validation-of-callsites-targeting-n4injector-methods">11.2.5. Validation of callsites targeting N4Injector methods</a></li>
<li><a href="extended_fetaures.html#_n4js-di-annotations">11.2.6. N4JS DI Annotations</a>
<ul class="sectlevel4">
<li><a href="extended_fetaures.html#_n4js-di-generateinjector">11.2.6.1. N4JS DI @GenerateInjector</a></li>
<li><a href="extended_fetaures.html#_n4js-di-withparentinjector">11.2.6.2. N4JS DI @WithParentInjector</a></li>
<li><a href="extended_fetaures.html#_n4js-di-usebinder">11.2.6.3. N4JS DI @UseBinder</a></li>
<li><a href="extended_fetaures.html#_n4js-di-binder">11.2.6.4. N4JS DI @Binder</a></li>
<li><a href="extended_fetaures.html#_n4js-di-bind">11.2.6.5. N4JS DI @Bind</a></li>
<li><a href="extended_fetaures.html#_n4js-di-provides">11.2.6.6. N4JS DI @Provides</a></li>
<li><a href="extended_fetaures.html#_n4js-di-inject">11.2.6.7. N4JS DI @Inject</a></li>
<li><a href="extended_fetaures.html#_n4js-di-singleton">11.2.6.8. N4JS DI @Singleton</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="extended_fetaures.html#_test-support">11.3. Test Support</a></li>
<li><a href="extended_fetaures.html#_polyfill-definitions">11.4. Polyfill Definitions</a>
<ul class="sectlevel3">
<li><a href="extended_fetaures.html#_runtime-polyfill-definitions">11.4.1. Runtime Polyfill Definitions</a></li>
<li><a href="extended_fetaures.html#_static-polyfill-definitions">11.4.2. Static Polyfill Definitions</a></li>
<li><a href="extended_fetaures.html#_transpiling-static-polyfilled-classes">11.4.3. Transpiling static polyfilled classes</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="components.html#_components">12. Components</a>
<ul class="sectlevel2">
<li><a href="components.html#_overview-2">12.1. Overview</a></li>
<li><a href="components.html#Component_Types">12.2. Component Types</a>
<ul class="sectlevel3">
<li><a href="components.html#_libraries">12.2.1. Libraries</a></li>
<li><a href="components.html#_runtime-environment-and-runtime-libraries">12.2.2. Runtime Environment and Runtime Libraries</a></li>
<li><a href="components.html#_tests">12.2.3. Tests</a></li>
<li><a href="components.html#_type-definitions">12.2.4. Type Definitions</a></li>
</ul>
</li>
<li><a href="components.html#package-json">12.3. Package.json File</a>
<ul class="sectlevel3">
<li><a href="components.html#_basic-properties">12.3.1. Basic Properties</a></li>
<li><a href="components.html#_n4js-properties">12.3.2. N4JS Properties</a></li>
<li><a href="components.html#_constraints">12.3.3. Constraints</a></li>
</ul>
</li>
<li><a href="components.html#_support-for-npm-scopes">12.4. Support for NPM Scopes</a></li>
<li><a href="components.html#sec:N4JS-Type-Definitions">12.5. N4JS Type Definitions</a>
<ul class="sectlevel3">
<li><a href="components.html#_specify-type-definition">12.5.1. Specify Type Definition</a></li>
<li><a href="components.html#_name-conventions">12.5.2. Name Conventions</a></li>
<li><a href="components.html#_version-conventions">12.5.3. Version Conventions</a>
<ul class="sectlevel4">
<li><a href="components.html#_define-a-new-type-definition-package">12.5.3.1. Define a New Type Definition Package</a></li>
<li><a href="components.html#_using-a-type-definition-package">12.5.3.2. Using a Type Definition Package</a></li>
<li><a href="components.html#_rational">12.5.3.3. Rational</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="components.html#_modules">12.6. Modules</a></li>
<li><a href="components.html#_api-and-implementation-component">12.7. API and Implementation Component</a>
<ul class="sectlevel3">
<li><a href="components.html#_execution-of-api-and-implementation-components">12.7.1. Execution of API and Implementation Components</a></li>
<li><a href="components.html#_api-and-implementation-with-di">12.7.2. API and Implementation With DI</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="plainjs.html#_plainjs">13. PlainJS</a>
<ul class="sectlevel2">
<li><a href="plainjs.html#_type-inference-and-validation-for-plain-js">13.1. Type Inference and Validation for Plain JS</a></li>
<li><a href="plainjs.html#_external-declarations">13.2. External Declarations</a>
<ul class="sectlevel3">
<li><a href="plainjs.html#_declaring-externals">13.2.1. Declaring externals</a></li>
<li><a href="plainjs.html#_instantiating-external-classes">13.2.2. Instantiating external classes</a></li>
<li><a href="plainjs.html#_implementation-of-external-declarations">13.2.3. Implementation of External Declarations</a></li>
<li><a href="plainjs.html#_example">13.2.4. Example</a></li>
</ul>
</li>
<li><a href="plainjs.html#_global-definitions">13.3. Global Definitions</a></li>
<li><a href="plainjs.html#_runtime-definitions">13.4. Runtime Definitions</a></li>
<li><a href="plainjs.html#_applying-polyfills">13.5. Applying Polyfills</a></li>
</ul>
</li>
<li><a href="jsdoc.html#_jsdoc-2">14. JSDoc</a>
<ul class="sectlevel2">
<li><a href="jsdoc.html#_general-n4jsdoc-features">14.1. General N4JSDoc Features</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#_provided-inline-tags">14.1.1. Provided Inline Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag__code">14.1.1.1. @code</a></li>
<li><a href="jsdoc.html#jsdoc_tag__link">14.1.1.2. @link</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="jsdoc.html#_n4jsdoc-for-user-projects">14.2. N4JSdoc for User Projects</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#_standard-tags">14.2.1. Standard Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#_-author">14.2.1.1. @author</a></li>
<li><a href="jsdoc.html#jsdoc_tag_param">14.2.1.2. @param</a></li>
<li><a href="jsdoc.html#jsdoc_tag_return">14.2.1.3. @return</a></li>
</ul>
</li>
<li><a href="jsdoc.html#_test-related-tags">14.2.2. Test Related Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag__testee">14.2.2.1. @testee</a></li>
<li><a href="jsdoc.html#jsdoc_tag__testeeFromType">14.2.2.2. @testeeFromType</a></li>
<li><a href="jsdoc.html#_testeeType_and__testeeMember">14.2.2.3. @testeeType and @testeeMember</a></li>
<li><a href="jsdoc.html#jsdoc_tag_reqid_in_Tests">14.2.2.4. @reqid in Tests</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="jsdoc.html#_n4jsdoc-for-api-and-implementation-projects">14.3. N4JSDoc for API and Implementation Projects</a>
<ul class="sectlevel3">
<li><a href="jsdoc.html#jsdoc_tag__apiNote">14.3.1. @apiNote</a></li>
<li><a href="jsdoc.html#API_Project_Tags">14.3.2. API Project Tags</a>
<ul class="sectlevel4">
<li><a href="jsdoc.html#jsdoc_tag_apiState">14.3.2.1. @apiState</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="jsx.html#_jsx">15. JSX</a>
<ul class="sectlevel2">
<li><a href="jsx.html#_jsx-support">15.1. JSX Support</a></li>
<li><a href="jsx.html#_jsx-backend">15.2. JSX Backend</a></li>
</ul>
</li>
<li><a href="grammars.html#_grammars">16. Grammars</a>
<ul class="sectlevel2">
<li><a href="grammars.html#_type-expressions-grammar">16.1. Type Expressions Grammar</a></li>
<li><a href="grammars.html#_n4js-language-grammar">16.2. N4JS Language Grammar</a></li>
</ul>
</li>
<li><a href="jsobjects.html#_jsobjects">17. JSObjects</a>
<ul class="sectlevel2">
<li><a href="jsobjects.html#_object">17.1. Object</a></li>
<li><a href="jsobjects.html#_string">17.2. String</a></li>
<li><a href="jsobjects.html#_boolean">17.3. Boolean</a></li>
<li><a href="jsobjects.html#_number">17.4. Number</a>
<ul class="sectlevel3">
<li><a href="jsobjects.html#_static-attributes">17.4.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="jsobjects.html#function">17.5. Function</a></li>
<li><a href="jsobjects.html#_error">17.6. Error</a></li>
<li><a href="jsobjects.html#_array">17.7. Array</a></li>
<li><a href="jsobjects.html#_date">17.8. Date</a></li>
<li><a href="jsobjects.html#_math">17.9. Math</a>
<ul class="sectlevel3">
<li><a href="jsobjects.html#static-attributes-1">17.9.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="jsobjects.html#_regexp">17.10. RegExp</a></li>
<li><a href="jsobjects.html#_json">17.11. JSON</a></li>
</ul>
</li>
<li><a href="n4js_objects.html#_n4js-objects">18. N4JS Objects</a>
<ul class="sectlevel2">
<li><a href="n4js_objects.html#_reflection-model">18.1. Reflection Model</a></li>
<li><a href="n4js_objects.html#_error-types">18.2. Error Types</a>
<ul class="sectlevel3">
<li><a href="n4js_objects.html#_n4apinotimplemented">18.2.1. N4ApiNotImplemented</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="appendix_a_acronyms.html#_acronyms">Appendix A: Acronyms</a></li>
<li><a href="appendix_b_license.html#sec:License">Appendix B: License</a></li>
<li><a href="appendix_c_bibliography.html#_bibliography">Appendix C: Bibliography</a></li>
</ul>
</div>
</div>
<div id="content"><div class="sect1">
<h2 id="_types"><a class="anchor" href="#_types"></a><a class="link" href="#_types">4. Types</a></h2>
<div class="sectionbody">
<div class="sect2 language-n4js">
<h3 id="_overview"><a class="anchor" href="#_overview"></a><a class="link" href="#_overview">4.1. Overview</a></h3>
<div class="paragraph">
<p>N4JS is essentially ECMAScript with the inclusion of types.
In the following sections we will describe how types are defined and used in N4JS.</p>
</div>
<div class="paragraph">
<p>Besides standard JavaScript types, the following metatypes are introduced:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Classifiers, that is class or interface (see <a href="classifiers.html#_classifiers">Classifiers</a>)</p>
</li>
<li>
<p>Enum</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Classifiers, methods and functions may be declared generic.</p>
</div>
<div class="paragraph">
<p>Types are related to each other by the subtype relation.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="subtype_relation"></a><strong>Definition:</strong> <a href="#subtype_relation">Subtype Relation</a></p>
</div>
<div class="paragraph">
<p>We use <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>b</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> for the general subtype relation or type conformance.</p>
</div>
<div class="paragraph">
<p>In nominal typing, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></math> means that <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math> is a (transitive) supertype of <em>T</em>.
Generally in structural typing, this means that <em>T</em> <em>conforms</em> to <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math>.
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/></math> is defined transitive reflexive by default.</p>
</div>
<div class="paragraph">
<p>We write <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>&lt;</mo></math> to refer to the transitive non-reflexive relation, that is <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mo>&lt;</mo><mi>S</mi><mo>⇔</mo><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi><mo>∧</mo><mi>T</mi><mo>≠</mo><mi>S</mi></math></p>
</div>
</div>
</div>
<div class="paragraph">
<p>Whether nominal or structural typing is used depends on the declaration of the type or the reference.
This is explained further in <a href="classifiers.html#_structural-typing">Structural Typing</a>.</p>
</div>
<div class="paragraph">
<p>For convenience reasons, we sometimes revert the operator, that is <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi><mo>⇔</mo><mi>S</mi><mi>:</mi><mo>&gt;</mo><mi>T</mi></math>.
We write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></math> if <em>T</em> is not type conforming to <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math>. (cf. [<a href="appendix_c_bibliography.html#Gosling12a">Gosling12a(p.S4.10)</a>])</p>
</div>
<div class="paragraph">
<p>Join and meet are defined as follows:</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="join_and_meet"></a><strong>Definition:</strong> <a href="#join_and_meet">Join and Meet</a></p>
</div>
<div class="paragraph">
<p>A type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> is called a <em>join</em> (or least common supertype, ) of a pair of types <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math> and <em>T</em>, written <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi><mo>∨</mo><mi>T</mi><mo>=</mo><mi>J</mi></math>, if</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>J</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>J</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>L</mi><mi>:</mi><mrow><mo>(</mo><mrow><mi>S</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>L</mi><mo>)</mo></mrow><mo>∧</mo><mrow><mo>(</mo><mrow><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>L</mi><mo>)</mo></mrow><mo>→</mo><mi>J</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>L</mi></mrow></mrow></math></p>
</div>
<div class="paragraph">
<p>Similarly, we say that a type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>M</mi></math> is a <em>meet</em> (or greatest common subtype, ) of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math> and <em>T</em>, written <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi><mo>∧</mo><mi>T</mi><mo>=</mo><mi>M</mi></math>, if<br></p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>M</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>M</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>L</mi><mi>:</mi><mrow><mo>(</mo><mrow><mi>L</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi><mo>)</mo></mrow><mo>∧</mo><mrow><mo>(</mo><mrow><mi>L</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi><mo>)</mo></mrow><mo>→</mo><mi>L</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>M</mi></mrow></mrow></math></p>
</div>
</div>
</div>
<div class="paragraph">
<p>Note that this declarative definition needs to be specified in detail for special cases, such as union and intersection types.
Usually, the union type of two types is also the join.</p>
</div>
<div class="paragraph">
<p><a href="#fig-cd-predefined-type-hierarchy">Predefined Types Hierarchy</a> summarizes all predefined types,
that is primitive and built-in ECMAScript and N4JS types.
Specific rules for the subtype relation are defined in the following sections.
This type hierarchy shows <code>any</code> and <code>undefined</code> as the top and bottom type (cf. [<a href="appendix_c_bibliography.html#Pierce02a">Pierce02a(p.15.4)</a>]) We define these types here explicitly:</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="top_and_bottom_type"></a><strong>Definition:</strong> <a href="#top_and_bottom_type">Top and Bottom Type</a></p>
</div>
<div class="paragraph">
<p>We call <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mi>o</mi><mi>p</mi></math> the top type, if for all types <em>T</em> the relation  <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi><mi>o</mi><mi>p</mi></math> is true.
We call <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mi>o</mi><mi>t</mi></math> the bottom type, if for all types <em>T</em> the relation <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mi>o</mi><mi>t</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi></math> is true.
In N4JS, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mi>o</mi><mi>p</mi><mo>=</mo><mi>a</mi><mi>n</mi><mi>y</mi></math>, the bottom type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mi>o</mi><mi>t</mi><mo>=</mo><mi>u</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>f</mi><mi>i</mi><mi>n</mi><mi>e</mi><mi>d</mi></math>.</p>
</div>
</div>
</div>
<div class="paragraph">
<p><code>null</code> is almost similar to <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mi>o</mi><mi>t</mi></math>, except that it is not a subtype of <code>undefined</code>.</p>
</div>
<div id="fig-cd-predefined-type-hierarchy" class="imageblock" style="text-align: center">
<div class="content">
<img src="chapters/04_types/fig/cdPredefinedTypesHierarchy.svg" alt="cdPredefinedTypesHierarchy">
</div>
<div class="title">Figure 2. Predefined Types Hierarchy</div>
</div>
<div class="paragraph">
<p>For every primitive type there is a corresponding built-in type as defined in [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a</a>], e.g. <code>string</code> and <code>String</code>.
There is no inheritance supported for primitive types and built-in types – these types are final.</p>
</div>
<div class="paragraph">
<p>Although the diagram shows inheritance between <code>void</code> and <code>undefined</code>, this relationship is only semantic: <code>void</code> is a refinement of <code>undefined</code> from a type system viewpoint.
The same applies to the relation of <code>Object</code> as well as the subtypes shown for <code>string</code> and <code>String</code>.</p>
</div>
<div id="ex:class-hierarchy" class="exampleblock">
<div class="title">Example 6. Type Examples, Class Hierarchy</div>
<div class="content">
<div class="paragraph">
<p>In the following examples, we assume the following classes to be given:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">// C &lt;: B &lt;: A
class A{}
class B extends A{}
class C extends B{}

// independent types X, Y, and Z
class X{} class Y{} class Z{}

// interfaces I, I1 &lt;: I, I2 &lt;: I, I3
interface I
interface I1 extends I {}
interface I2 extends I {}
interface I3 {}

// class implementing the interfaces
class H1 implements I1{}
class H12 implements I1,I2{}
class H23 implements I2,I3{}

// a generic class with getter (contra-variance) and setter (co-variance)
class G&lt;T&gt; {
    get(). T;
    set(x: T): void;
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_type-expressions"><a class="anchor" href="#_type-expressions"></a><a class="link" href="#_type-expressions">4.2. Type Expressions</a></h3>
<div class="paragraph">
<p>In contrast to ECMAScript, N4JS defines static types.
Aside from simple type references, type expressions may be used to specify the type of variables.</p>
</div>
<div class="sect3">
<h4 id="_syntax"><a class="anchor" href="#_syntax"></a><a class="link" href="#_syntax">4.2.1. Syntax</a></h4>
<div class="paragraph">
<p>The listing <a href="grammars.html#lst:EBNFTypeExpression">EBNF Type Expression Grammar</a> summarizes the type expression grammar.
Depending on the context, not all constructs are allowed.
For example, the variadic modifier is only allowed for function parameters.</p>
</div>
<div class="paragraph">
<p>References to user-declared types are expressed via <code>ParameterizedTypeRef</code>.
This is also true for non-generic types, as the type arguments are optional.
See <a href="#_parameterized-types">Parameterized Types</a> for details on that reference.</p>
</div>
<div class="paragraph">
<p>For qualified names and type reference names, see <a href="names.html#_qualified-names">Qualified Names</a></p>
</div>
<div class="paragraph">
<p>The type expressions are usually added to parameter, field, or variable declarations as a suffix, separated with colon (<code>:</code>).
The same is true for function, method, getter or setter return types.
Exceptions in the cases of object literals or destructuring are explained later on.</p>
</div>
<div class="exampleblock">
<div class="title">Example 7. Type Annotation Syntax</div>
<div class="content">
<div class="paragraph">
<p>The following two listings show the very same code and type annotations are provided on
the left hand side. For simplicity, <code>string</code> is always used as type expression.<sup class="footnote">[<a id="_footnoteref_10" class="footnote" href="appendix_c_bibliography.html#_footnote_10" title="View footnote.">10</a>]</sup></p>
</div>
<table class="tableblock frame-none grid-none spread">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div><div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var x: string;
var s: string = "Hello";
function f(p: string): string {
    return p;
}
class C {
    f: string;
    s: string = "Hello";
    m(p: string): string {
        return p;
    }
    get x(): string {
        return this.f;
    }
    set x(v: string) {
        this.f = v;
    }
}</code></pre>
</div>
</div></div></td>
<td class="tableblock halign-left valign-top"><div><div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var x;
var s = "Hello";
function f(p) {
    return p;
}
class C {
    f;
    s = "Hello";
    m(p) {
        return p;
    }
    get x() {
        return this.f;
    }
    set x(v) {
        this.f = v;
    }
}</code></pre>
</div>
</div></div></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>The code on the right hand side is almost all valid ECMAScript 2015, with the exception of field declarations in the class.
These are moved into the constructor by the N4JS transpiler.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_properties"><a class="anchor" href="#_properties"></a><a class="link" href="#_properties">4.2.2. Properties</a></h4>
<div class="paragraph">
<p>Besides the properties indirectly defined by the grammar, the following pseudo properties are used for type expressions:</p>
</div>
<div class="paragraph">
<p>Properties of <code>TypeExpression</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi><mi>a</mi><mi>r</mi></math> </dt>
<dd>
<p>If true, variable of that type is variadic. This is only allowed for parameters. Default value: <code>false</code>.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>o</mi><mi>p</mi><mi>t</mi></math> </dt>
<dd>
<p>If true, variable of that type is optional. This is only allowed for parameters and return types.
This actually means that the type <em>T</em> actually is a union type of <code>Undef|<em>T</em></code>.
Default value: <code>false</code>.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>o</mi><mi>p</mi><mi>t</mi><mi>v</mi><mi>a</mi><mi>r</mi></math> </dt>
<dd>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>o</mi><mi>p</mi><mi>t</mi><mi>v</mi><mi>a</mi><mi>r</mi><mo>=</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>∨</mo><mi>o</mi><mi>p</mi><mi>t</mi></math>, reflect the facts that a variadic parameter is also optional (as its cardinality is <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mfenced close="]" open="["><mrow><mn>0</mn><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mi>n</mi></mrow></mfenced><mo>)</mo></mrow><mo>.</mo></math></p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>e</mi><mi>n</mi><mi>t</mi><mi>i</mi><mi>t</mi><mi>y</mi></math> </dt>
<dd>
<p>Pseudo property referencing the variable declaration (or expression) which <code>owns</code> the type expression.</p>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="_semantics"><a class="anchor" href="#_semantics"></a><a class="link" href="#_semantics">4.2.3. Semantics</a></h4>
<div class="paragraph">
<p>The ECMAScript types <em>undefined</em> and <em>null</em> are also supported.
These types cannot be referenced directly, however.
Note that <code>void</code> and <em>undefined</em> are almost similar.
Actually, the inferred type of a types element with declared type of <code>void</code> will be <em>undefined</em>.
The difference between void and undefined is that an element of type void can never have another type,
while an element of type undefined may be assigned a value later on and thus become a different type.
<code>void</code> is only used for function and method return types.</p>
</div>
<div class="paragraph">
<p>Note that not any type reference is allowed in any context.
Variables or formal parameters must not be declared <code>void</code> or union types must not be declared dynamic, for example.
These constraints are explained in the following section.</p>
</div>
<div class="paragraph">
<p>The types mentioned above are described in detail in the next sections.
They are hierarchically defined and the following list displays all possible types.
Note that all types are actually references to types.
A type variable can only be used in some cases, e.g., the variable has to be visible in the given scope.</p>
</div>
<h5 id="_ecmascript-types" class="discrete">ECMAScript Types</h5>
<div class="dlist">
<dl>
<dt class="hdlist1">Predefined Type</dt>
<dd>
<p>Predefined types, such as String, Number, or Object; and .</p>
</dd>
<dt class="hdlist1">Array Type</dt>
<dd>
<p><a href="#_array-object-type">Array Object Type</a>.</p>
</dd>
<dt class="hdlist1">Function Type</dt>
<dd>
<p>Described in <a href="functions.html#_functions">Functions</a>, <a href="functions.html#_function-type">Function Type</a>.</p>
</dd>
<dt class="hdlist1">Any Type</dt>
<dd>
<p><a href="#_any-type">Any Type</a>.</p>
</dd>
</dl>
</div>
<h5 id="_n4types" class="discrete">N4Types</h5>
<div class="dlist">
<dl>
<dt class="hdlist1">Declared Type</dt>
<dd>
<p>(Unparameterized) Reference to defined class <a href="classifiers.html#_classes">Classes</a> or enum <a href="#_enums">Enums</a>.</p>
</dd>
<dt class="hdlist1">Parameterized Type</dt>
<dd>
<p>Parameterized reference to defined generic class or interface; <a href="#_parameterized-types">Parameterized Types</a>.</p>
</dd>
<dt class="hdlist1">This Type</dt>
<dd>
<p><a href="#_this-type">This Type</a>.</p>
</dd>
<dt class="hdlist1">Constructor and Type Type</dt>
<dd>
<p>Class type, that is the meta class of a defined class or interface, <a href="#_constructor-and-classifier-type">Constructor and Classifier Type</a>.</p>
</dd>
<dt class="hdlist1">Union Types</dt>
<dd>
<p>Union of types, <a href="#_union-type">Union Type</a>.</p>
</dd>
<dt class="hdlist1">Type Variable</dt>
<dd>
<p>Type variable, <a href="#_type-variables">Type Variables</a>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Type expressions are used to explicitly declare the type of a variable, parameter and return type of a function or method, fields (and object literal properties).</p>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_type-inference"><a class="anchor" href="#_type-inference"></a><a class="link" href="#_type-inference">4.3. Type Inference</a></h3>
<div class="paragraph">
<p>If no type is explicitly declared, it is inferred based on the given context, as in the expected type of expressions or function parameters, for example.
The type inference rules are described in the remainder of this specification.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="default_type"></a><strong>Definition:</strong> <a href="#default_type">Default Type</a></p>
</div>
<div class="paragraph">
<p>In N4JS mode , if no type is explicitly specified and if no type information can be inferred, <code>any</code> is assumed as the default type.</p>
</div>
<div class="paragraph">
<p>In JS mode, the default type is <code>any+</code>.</p>
</div>
<div class="paragraph">
<p>Once the type of a variable is either declared or inferred, it is not supposed to be changed.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>Given the following example.</p>
</div>
<div class="listingblock">
<div class="title">Variable type is not changeable</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var x: any;
x = 42;
x-5; // error: any is not a subtype of number.</code></pre>
</div>
</div>
<div class="paragraph">
<p>Type of <code>x</code> is declared as <code>any</code> in line 1. Although a number is assigned to <code>x</code> in line 2, the type of <code>x</code> is not changed. Thus an error is issued in line 3 because the type of <code>x</code> is still <code>any</code>.</p>
</div>
<div class="paragraph todo">
<p>At the moment, N4JS does not support type guards or, more general, effect system (cf. [<a href="appendix_c_bibliography.html#Nielson99a">Nielson99a</a>]).</p>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_generic-and-parameterized-types"><a class="anchor" href="#_generic-and-parameterized-types"></a><a class="link" href="#_generic-and-parameterized-types">4.4. Generic and Parameterized Types</a></h3>
<div class="paragraph">
<p>Some notes on terminology:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Type Parameter vs. Type Argument</dt>
<dd>
<p>A type parameter is a declaration containing type variables.
A type argument is a binding of a type parameter to a concrete type or to another type parameter.
Binding to another type parameter can further restrict the bounds of the type parameter.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>This is similar to function declarations (with formal parameters) and function calls (with arguments).</p>
</div>
<div class="sect3">
<h4 id="_generic-types"><a class="anchor" href="#_generic-types"></a><a class="link" href="#_generic-types">4.4.1. Generic Types</a></h4>
<div class="paragraph">
<p>A class declaration or interface declaration with type parameters declares a generic type.
A generic type declares a family of types.
The type parameters have to be bound with type arguments when referencing a generic type.</p>
</div>
</div>
<div class="sect3">
<h4 id="_type-variables"><a class="anchor" href="#_type-variables"></a><a class="link" href="#_type-variables">4.4.2. Type Variables</a></h4>
<div class="paragraph">
<p>A type variable is an identifier used as a type in the context of a generic class definition, generic interface definition or generic method definition.
A type variable is declared in a type parameter as follows.</p>
</div>
<h5 id="_syntax-2" class="discrete">Syntax</h5>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">TypeVariable:
	(declaredCovariant?='out' | declaredContravariant?='in')?
	name=IdentifierOrThis ('extends' declaredUpperBound=TypeRef)?
;</code></pre>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 8. Type Variable as Upper Bound</div>
<div class="content">
<div class="paragraph">
<p>Note that type variables are also interpreted as types.
Thus, the upper bound of a type variable may be a type variable as shown in the following snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class G&lt;T&gt; {
    &lt;X extends T&gt; foo(x: X): void { }
}</code></pre>
</div>
</div>
</div>
</div>
<h5 id="type-variables-properties" class="discrete">Properties</h5>
<div class="paragraph">
<p>A type parameter defines a type variable, which type may be constrained with an upper bound.</p>
</div>
<div class="paragraph">
<p>Properties of <code>TypeVariable</code>:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></math> </dt>
<dd>
<p>Type variable, as type variable contains only an identifier, we use type parameter instead of type variable (and vice versa) if the correct element is clear from the context.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi></math> </dt>
<dd>
<p>Upper bound of the concrete type being bound to this type variable, i.e. a super class.</p>
</dd>
</dl>
</div>
<h5 id="type-variables-semantics" class="discrete">Semantics</h5>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-10"></a><strong>Req. IDE-10:</strong> <a href="#Req-IDE-10">Type Variable Semantics</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Enum is not a valid metatype in <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></math>.</p>
</li>
<li>
<p>Wildcards are not valid in <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></math>.</p>
</li>
<li>
<p>Primitives are not valid in <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></math>.</p>
</li>
<li>
<p>Type variables are valid in <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></math>.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="paragraph">
<p>A type variable can be used in any type expression contained in the generic class, generic interface, or generic function / method definition.</p>
</div>
<div class="exampleblock">
<div class="title">Example 9. F bounded quantification</div>
<div class="content">
<div class="paragraph">
<p>Using a type variable in the upper bound reference may lead to recursive definition.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class Chain&lt;C extends Chain&lt;C, T&gt;, T&gt; {
    next() : C { return null; }
    m() : T { return null; }
}</code></pre>
</div>
</div>
</div>
</div>
<h5 id="type-variables-type-inference" class="discrete">Type Inference</h5>
<div class="paragraph">
<p>In many cases, type variables are not directly used in subtype relations as they are substituted with the concrete types specified by some type arguments.
In these cases, the ordinary subtype rules apply without change.
However, there are other cases in which type variables cannot be substituted:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Inside a generic declaration.</p>
</li>
<li>
<p>If the generic type is used as raw type.</p>
</li>
<li>
<p>If a generic function / method is called without type arguments and without the possibility to infer the type from the context.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>In these cases, an unbound type variable may appear on one or both sides of a subtype relation and we require subtype rules that take type variables into account.</p>
</div>
<div class="paragraph">
<p>It is important to note that while type variables may have a declared upper bound, they cannot be simply replaced with that upper bound and treated like existential types.
The following example illustrates this:</p>
</div>
<div class="exampleblock">
<div class="title">Example 10. Type variables vs. existential types</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {}
class B extends A {}
class C extends B {}

class G&lt;T&gt; {}

class X&lt;T extends A, S extends B&gt; {

    m(): void {

        // plain type variables:
        var t: T;
        var s: S;

        t = s;  // ERROR: "S is not a subtype of T." at "s" <i class="conum" data-value="1"></i><b>(1)</b>

        // existential types:
        var ga: G&lt;? extends A&gt;;
        var gb: G&lt;? extends B&gt;;

        ga = gb;  <i class="conum" data-value="2"></i><b>(2)</b>
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Even though the upper bound of <code>S</code> is a subtype of <code>T</code>’s upper bound (since <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math>), we cannot infer that <code>S</code> is a subtype of <code>T</code>,
because there are valid concrete bindings for which this would not be true: for example, if <code>T</code> were bound to <code>C</code> and <code>S</code> to <code>B</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>This differs from existential types (see <code>ga</code> and <code>gb</code> and line 21):<br>
<code>G&lt;? extends B&gt;</code> <math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/></math> <code>G&lt;? extends A&gt;</code> ).</td>
</tr>
</table>
</div>
</div>
</div>
<div class="paragraph">
<p>We thus have to define subtype rules for type variables, taking the declared upper bound into account.
If we have a subtype relation in which a type variable appears on one or both sides, we distinguish the following cases:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>If we have type variables on both sides: the result is true if and only if there is the identical type variable on both sides.</p>
</li>
<li>
<p>If we have a type variable on the left side and no type variable on the right side:<br>
the result is true if and only if the type variable on the left has one or more declared upper bounds.<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close=")" open="("><mrow><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></mrow></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi></math><br>
This is the case for</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfenced close=")" open="("><mrow><mi>T</mi><mspace width="3.0mm"/><mi>e</mi><mi>x</mi><mi>t</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>s</mi><mspace width="3.0mm"/><mi>B</mi></mrow></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math>
</div>
</div>
<div class="paragraph">
<p>in which T is an unbound type variable and A, B two classes with <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math>.</p>
</div>
</li>
<li>
<p>In all other cases the result is false.<br>
This includes cases such as</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mfenced close=")" open="("><mrow><mi>T</mi><mspace width="3.0mm"/><mi>e</mi><mi>x</mi><mi>t</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>s</mi><mspace width="3.0mm"/><mi>A</mi></mrow></mfenced></math>
</div>
</div>
<div class="paragraph">
<p>which is always false, even if <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math> or</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfenced close=")" open="("><mrow><mi>T</mi><mspace width="3.0mm"/><mi>e</mi><mi>x</mi><mi>t</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>s</mi><mspace width="3.0mm"/><mi>A</mi></mrow></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mfenced close=")" open="("><mrow><mi>S</mi><mspace width="3.0mm"/><mi>e</mi><mi>x</mi><mi>t</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>s</mi><mspace width="3.0mm"/><mi>B</mi></mrow></mfenced></math>
</div>
</div>
<div class="paragraph">
<p>which is always false, even if <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>=</mo><mi>B</mi></math>.</p>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>We thus obtain the following defintion:</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="subtype_relation_for_type_variables"></a><strong>Definition:</strong> <a href="#subtype_relation_for_type_variables">Subtype Relation for Type Variables</a></p>
</div>
<div class="paragraph">
<p>For two types <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mo>,</mo><mi>S</mi></math> of which at least one is a type variable, we define</p>
</div>
<div class="ulist">
<ul>
<li>
<p>if both <em>T</em> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math> are type variables:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>T</mi><mo>=</mo><mi>S</mi></mrow><mrow><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>if <em>T</em> is a type variable and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math> is not:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mrow><mi>T</mi><mo>.</mo><mstyle mathvariant="italic"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></mstyle><mo>.</mo><mstyle mathvariant="italic"><mi>s</mi><mi>i</mi><mi>z</mi><mi>e</mi></mstyle><mo>&gt;</mo><mn>0</mn></mrow><mrow><mi> </mi><mo>∧</mo><mi> </mi><mo>∀</mo><mi>t</mi><mo>∈</mo><mi>T</mi><mo>.</mo><mstyle mathvariant="italic"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>U</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>s</mi></mstyle><mi>:</mi><mi>t</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow></mrow><mrow><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow></mfrac></math>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_parameterized-types"><a class="anchor" href="#_parameterized-types"></a><a class="link" href="#_parameterized-types">4.4.3. Parameterized Types</a></h4>
<div class="paragraph">
<p>References to generic types (cf. <a href="classifiers.html#_classes">Classes</a>) can be parameterized with type arguments.
A type reference with type arguments is called parameterized type.</p>
</div>
<h5 id="parameterized-types-syntax" class="discrete">Syntax</h5>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ParameterizedTypeRef:
    ParameterizedTypeRefNominal | ParameterizedTypeRefStructural;

ParameterizedTypeRefNominal:
    declaredType=[Type|TypeReferenceName]
    (=&gt; '&lt;' typeArgs+=TypeArgument (',' typeArgs+=TypeArgument)* '&gt;')?;

ParameterizedTypeRefStructural:
    definedTypingStrategy=TypingStrategyUseSiteOperator
    declaredType=[Type|TypeReferenceName]
    (=&gt;'&lt;' typeArgs+=TypeArgument (',' typeArgs+=TypeArgument)* '&gt;')?
    ('with' TStructMemberList)?;

TypeArgument returns TypeArgument:
    Wildcard | TypeRef;

Wildcard returns Wildcard:
    '?'
    (
          'extends' declaredUpperBound=TypeRef
        | 'super' declaredLowerBound=TypeRef
    )?
;</code></pre>
</div>
</div>
<h5 id="parameterized-types-properties" class="discrete">Properties</h5>
<div class="paragraph">
<p>Properties of parameterized type references (nominal or structural):</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>declaredType</code> </dt>
<dd>
<p>Referenced type by type reference name (either the simple name or a qualified name, e.g. in case of namespace imports).</p>
</dd>
<dt class="hdlist1"><code>typeArgs</code> </dt>
<dd>
<p>The type arguments, may be empty.</p>
</dd>
<dt class="hdlist1"><code>definedTypingStrategy</code> </dt>
<dd>
<p>Typing strategy, by default nominal, see <a href="classifiers.html#_structural-typing">Structural Typing</a> for details</p>
</dd>
<dt class="hdlist1"><code>structuralMembers</code> </dt>
<dd>
<p>in case of structural typing, reference can add additional members to the structural type, see <a href="classifiers.html#_structural-typing">Structural Typing</a> for details.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p><strong>Pseudo Properties:</strong></p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>importSpec</code> </dt>
<dd>
<p>The <code>ImportSpecifier</code>, may be null if this is a local type reference.
Note that this may be a <code>NamedImportSpecifier</code>. See <a href="statements.html#_import-statement">Import Statement</a> for details for details.</p>
</dd>
<dt class="hdlist1"><code>moduleWideName</code> </dt>
<dd>
<p>Returns simple name of type, that is either the simple name as declared, or the alias in case of an imported type with alias in the import statement.</p>
</dd>
</dl>
</div>
<h5 id="parameterized-types-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>The main purpose of a parameterized type reference is to simply refer to the declared type.
If the declared type is a generic type, the parameterized type references defines a <em>substitution</em> of the type parameters of a generic type with actual type arguments.
A type argument can either be a concrete type, a wildcard or a type variable declared in the surrounding generic declaration.
The actual type arguments must conform to the type parameters so that code referencing the generic type parameters is still valid.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-11"></a><strong>Req. IDE-11:</strong> <a href="#Req-IDE-11">Parameterized Types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given parameterized type reference <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi></math> with <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi><mo>=</mo><mi>R</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math>, the following constraints must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The actual type arguments must conform to the type parameters, that is:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>|</mo><mi>G</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>P</mi><mi>a</mi><mi>r</mi><mi>s</mi><mo>|</mo><mo>=</mo><mo>|</mo><mi>R</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><mi>g</mi><mi>s</mi><mo>|</mo></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∧</mo><mo>∀</mo><mi> </mi><mi>i</mi><mo>,</mo><mn>0</mn><mo>&lt;</mo><mi>i</mi><mo>&lt;</mo><mo>|</mo><mi>R</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><mi>g</mi><mi>s</mi><mo>|</mo><mi>:</mi><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mrow><mi>R</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><mi>g</mi><msub><mi>s</mi><mi>i</mi></msub></mrow><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mrow><mi>R</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>P</mi><mi>a</mi><mi>r</mi><msub><mi>s</mi><mi>i</mi></msub></mrow><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow></math></p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>We define type erasure similar to Java [<a href="appendix_c_bibliography.html#Gosling12a">Gosling12a(p.S4.6)</a>] as 'mapping from types (possibly including parameterized types and type variables)
to types (that are never parameterized types or type variables)'. We write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math><sup>o</sup>
for the erasure of type <em>T</em>.<sup class="footnote">[<a id="_footnoteref_11" class="footnote" href="appendix_c_bibliography.html#_footnote_11" title="View footnote.">11</a>]</sup></p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="parameterized_type"></a><strong>Definition:</strong> <a href="#parameterized_type">Parameterized Type</a></p>
</div>
<div class="paragraph">
<p>A parameterized type reference <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi></math> defines a parameterized type <em>T</em>, in which all type parameters of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> are substituted with the actual values of the type arguments.
We call the type <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>T</mi><mn>0</mn></msup></math>, in which all type parameters of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> are ignored, the <em>raw type</em> or <em>erasure</em> of <em>T</em>.</p>
</div>
<div class="paragraph">
<p>We define for types in general:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The erasure <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi></math><sup>o</sup> of a parameterized type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi><mo>&lt;</mo><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>&gt;</mo></math> is simply <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi></math>.</p>
</li>
<li>
<p>The erasure of a type variable is the erasure of its upper bound.</p>
</li>
<li>
<p>The erasure of any other type is the type itself.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>This concept of type erasure is purely defined for specification purposes.
It is not to be confused with the <code>real</code> type erasure which takes place at runtime, in which almost no types (except primitive types) are available.</p>
</div>
<div class="paragraph">
<p>That is, the type reference in <code>var G&lt;string&gt; gs;</code> actually defines a type <code>G&lt;string&gt;</code>, so that <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mrow><mi>g</mi><mi>s</mi></mrow><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow><mo>=</mo><mstyle mathvariant="monospace"><mtext>G</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mo>&gt;</mo></math>.
It may reference a type defined by a class declaration <code>class G&lt;T&gt;</code>.
It is important that the type <code>G&lt;string&gt;</code> is different from <code>G&lt;T&gt;</code>.</p>
</div>
<div class="paragraph">
<p>If a parameterized type reference <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi></math> has no type arguments, then it is similar to the declared type.
That is, <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mi>R</mi><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow><mo>=</mo><mi>T</mi><mo>=</mo><mi>R</mi><mo>.</mo><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> if (and only if) <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>|</mo><mi>R</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><mi>g</mi><mi>s</mi><mo>|</mo><mo>=</mo><mn>0</mn></math>.</p>
</div>
<div class="paragraph">
<p>In the following, we do not distinguish between parameter type reference and parameter type – they are both two sides of the same coin.</p>
</div>
<div class="exampleblock">
<div class="title">Example 11. Raw Types</div>
<div class="content">
<div class="paragraph">
<p>In Java, due to backward compatibility (generics were only introduced in Java 1.5), it is possible to use raw types in which we refer to a generic type without specifying any type arguments.
This is not possible in N4JS, as there is no unique interpretation of the type in that case as shown in the following example.
Given the following declarations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A{}
class B extends A{}
class G&lt;T extends A&gt; { t: T; }
var g: G;</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>In this case, variable <code>g</code> refers to the <em>raw type</em> <code>G</code>.
This is forbidden in N4JS, because two interpretations are possible:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><code>g</code> is of type <code>G&lt;?  extends&gt;</code></p>
</li>
<li>
<p><code>g</code> is of type <code>G&lt;A&gt;</code></p>
</li>
</ol>
</div>
<div class="paragraph">
<p>In the first case, an existential type would be created, and <code>g.t = new A();</code> must fail.</p>
</div>
<div class="paragraph">
<p>In the second case, <code>g = new G&lt;B&gt;();</code> must fail.</p>
</div>
<div class="paragraph">
<p>In Java, both assignments work with raw types, which is not really safe.
To avoid problems due to different interpretations, usage of raw types
is not allowed in N4JS. <sup class="footnote">[<a id="_footnoteref_12" class="footnote" href="appendix_c_bibliography.html#_footnote_12" title="View footnote.">12</a>]</sup></p>
</div>
<div class="paragraph">
<p>Calls to generic functions and methods can also be parameterized, this is described in <a href="expressions.html#_function-calls">Function Calls</a>.
Note that invocation of generic functions or methods does not need to be parameterized.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="type_conformance"></a><strong>Definition:</strong> <a href="#type_conformance">Type Conformance</a></p>
</div>
<div class="paragraph">
<p>We define type conformance for non-primitive type references as follows:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>For two non-parameterized types <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>T</mi><mn>0</mn></msup></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>S</mi><mn>0</mn></msup></math>,</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><msup><mi>S</mi><mn>0</mn></msup><mo>∈</mo><msup><mi>T</mi><mn>0</mn></msup><mo>.</mo><mi>s</mi><mi>u</mi><msup><mi>p</mi><mo>*</mo></msup><mo>∪</mo><msup><mi>T</mi><mn>0</mn></msup><mo>.</mo><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><msup><mi>s</mi><mo>*</mo></msup></mrow><mrow><msup><mi>T</mi><mn>0</mn></msup><mo>&lt;</mo><mi>:</mi><msup><mi>S</mi><mn>0</mn></msup></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>For two parameterized types <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi><mo>&lt;</mo><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>&gt;</mo></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi><mo>&lt;</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>m</mi></msub><mo>&gt;</mo></math></p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><msup><mi>T</mi><mn>0</mn></msup><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><msup><mi>S</mi><mn>0</mn></msup></mrow><mrow><mspace width="10.0em"/><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi><mspace width="10.0em"/></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>(</mo><mi>n</mi><mo>=</mo><mn>0</mn><mo>∨</mo><mi>m</mi><mo>=</mo><mn>0</mn><mo>∨</mo><mrow><mo>(</mo><mi>n</mi><mo>=</mo><mi>m</mi><mo>→</mo><mo>∀</mo><mi>i</mi><mi>:</mi></mrow></mrow></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><mrow><msub><mi>T</mi><mi>i</mi></msub><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><msub><mi>S</mi><mi>i</mi></msub><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi></mrow></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mrow><mspace width="1.0em"/><mo>∧</mo><mrow><msub><mi>T</mi><mi>i</mi></msub><mo>.</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi><mi>:</mi><mo>&gt;</mo><msub><mi>S</mi><mi>i</mi></msub><mo>.</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mi>B</mi><mi>o</mi><mi>u</mi><mi>n</mi><mi>d</mi></mrow><mo>)</mo></mrow><mo>)</mo></mrow><mi>}</mi></math></p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 12. Subtyping with parameterized types</div>
<div class="content">
<div class="paragraph">
<p>Let classes A, B, and C are defined as in the chapter beginning (<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math>).
The following subtype relations are evaluated as indicated:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">G&lt;A&gt; &lt;: G&lt;B&gt;                        -&gt; false
G&lt;B&gt; &lt;: G&lt;A&gt;                        -&gt; false
G&lt;A&gt; &lt;: G&lt;A&gt;                        -&gt; true
G&lt;A&gt; &lt;: G&lt;?&gt;                        -&gt; true
G&lt;? extends A&gt; &lt;: G&lt;? extends A&gt;    -&gt; true
G&lt;? super A&gt; &lt;: G&lt;? super A&gt;        -&gt; true
G&lt;? extends A&gt; &lt;: G&lt;? extends B&gt;    -&gt; false
G&lt;? extends B&gt; &lt;: G&lt;? extends A&gt;    -&gt; true
G&lt;? super A&gt; &lt;: G&lt;? super B&gt;        -&gt; true
G&lt;? super B&gt; &lt;: G&lt;? super A&gt;        -&gt; false
G&lt;? extends A&gt; &lt;: G&lt;A&gt;              -&gt; false
G&lt;A&gt; &lt;: G&lt;? extends A&gt;              -&gt; true
G&lt;? super A&gt; &lt;: G&lt;A&gt;                -&gt; false
G&lt;A&gt; &lt;: G&lt;? super A&gt;                -&gt; true
G&lt;? super A&gt; &lt;: G&lt;? extends A&gt;      -&gt; false
G&lt;? extends A&gt; &lt;: G&lt;? super A&gt;      -&gt; false
G&lt;?&gt; &lt;: G&lt;? super A&gt;                -&gt; false
G&lt;? super A&gt; &lt;: G&lt;?&gt;                -&gt; true
G&lt;?&gt; &lt;: G&lt;? extends A&gt;              -&gt; false
G&lt;? extends A&gt; &lt;: G&lt;?&gt;              -&gt; true</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The figure <a href="#cdVarianceChart">Cheat Sheet: Subtype Relation of Parameterized Types</a> shows the subtype relations of parameterized types (of a single generic type), which can be used as a cheat sheet.</p>
</div>
<div id="cdVarianceChart" class="imageblock" style="text-align: center">
<div class="content">
<img src="chapters/04_types/fig/cdVarianceChart.svg" alt="cdVarianceChart">
</div>
<div class="title">Figure 3. Cheat Sheet: Subtype Relation of Parameterized Types</div>
</div>
<div class="exampleblock">
<div class="title">Example 13. Subtyping between different generic types</div>
<div class="content">
<div class="paragraph">
<p>Let classes <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>H</mi></math> be two generic classes where:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class G&lt;T&gt; {}
class H&lt;T&gt; extends G&lt;T&gt; {}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Given a simple, non-parameterized class <em>A</em>, the following
subtype relations are evaluated as indicated:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">G&lt;A&gt; &lt;: G&lt;A&gt;                        -&gt; true
H&lt;A&gt; &lt;: G&lt;A&gt;                        -&gt; true
G&lt;A&gt; &lt;: H&lt;A&gt;                        -&gt; false</code></pre>
</div>
</div>
</div>
</div>
<h5 id="parameterized-types-type-inference" class="discrete">Type Inference</h5>
<div class="paragraph">
<p>Type inference for parameterized types uses the concept of existential types (in Java, a slightly modified version called capture conversion is implemented).</p>
</div>
<div class="paragraph">
<p>The general concept for checking type conformance and inferring types for generic and parameterized types is described in [<a href="appendix_c_bibliography.html#Igarashi01a">Igarashi01a</a>] for <em>Featherweight Java with Generics</em>.</p>
</div>
<div class="paragraph">
<p>The concept of existential types with wildcard capture (a special kind of existential type) is published in [<a href="appendix_c_bibliography.html#Torgersen05a">Torgersen05a</a>], further developed in [<a href="appendix_c_bibliography.html#Cameron08b">Cameron08b</a>] (further developed in  [<a href="appendix_c_bibliography.html#Cameron09a">Cameron09a</a>] [<a href="appendix_c_bibliography.html#Summers10a">Summers10a</a>], also see [<a href="appendix_c_bibliography.html#Wehr08a">Wehr08a</a>] for a similar approach).
The key feature of the Java generic wildcard handling is called capture conversion, described in [<a href="appendix_c_bibliography.html#Gosling12a">Gosling12a(p.S5.1.10)</a>].
However, there are some slight differences to Java 6 and 7, only with Java 8 similar results can be expected.
All these papers include formal proofs of certain aspects, however even these paper lack proof of other aspect</p>
</div>
<div class="paragraph">
<p>The idea is quite simple: All unbound wildcards are replaced with freshly created new types <sup class="footnote">[<a id="_footnoteref_13" class="footnote" href="appendix_c_bibliography.html#_footnote_13" title="View footnote.">13</a>]</sup>,
fulfilling the constraints defined by the wildcard’s upper and lower bound.
These newly created types are then handled similar to real types during type inference and type conformance validation.</p>
</div>
<div class="exampleblock">
<div class="title">Example 14. Existential Type</div>
<div class="content">
<div class="paragraph">
<p>The inferred type of a variable
declared as</p>
</div>
<div class="paragraph">
<p><code>var x: G&lt;? extends A&gt;;</code>,</p>
</div>
<div class="paragraph">
<p>that is the parameterized type, is an existential type <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mn>1</mn></msub></math>, which is a subtype of A.
If you have another variable declared as</p>
</div>
<div class="paragraph">
<p><code>var y: G&lt;? extends A&gt;;</code></p>
</div>
<div class="paragraph">
<p>another type <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mn>2</mn></msub></math> is created, which is also a subtype of A.
Note that <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mn>1</mn></msub><mo>≠</mo><msub><mi>E</mi><mn>2</mn></msub></math>! Assuming typical setter or getter in G, e.g. <code>set(T t)</code> and <code>T get()</code>, the following code snippet will produce an error:</p>
</div>
<div class="paragraph">
<p><code>y.set(x.get())</code></p>
</div>
<div class="paragraph">
<p>This is no surprise, as <code>x.get()</code> actually returns a type <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mn>1</mn></msub></math>, which is not a subtype of <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mn>2</mn></msub></math>.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>The upper and lower bound declarations are, of course, still available during type inference for these existential types.
This enables the type inferencer to calculate the join and meet of parameterized types as well.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-12"></a><strong>Req. IDE-12:</strong> <a href="#Req-IDE-12">Join of Parameterized Types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The join of two parameterized types <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>G</mi><mo>&lt;</mo><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>&gt;</mo></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>H</mi><mo>&lt;</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>m</mi></msub><mo>&gt;</mo></math> is the join of the raw types, this join is then parameterized with the join of the
upper bounds of of type arguments and the meet of the lower bounds of the type arguments.</p>
</div>
<div class="paragraph">
<p>For all type rules, we assume that the upper and lower bounds of a non-generic type, including type variables,
simply equal the type itself, that is for a given type <em>T</em>, the following constraints hold:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>=</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>=</mo><mi>T</mi></math></p>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 15. Upper and lower bound of parameterized types</div>
<div class="content">
<div class="paragraph">
<p>Assuming the given classes listed above, the following upper and lower bounds are expected:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">G&lt;A&gt;            -&gt; upperBound = lowerBound = A
G&lt;? extends A&gt;  -&gt; lowerBound = null, upperBound = A
G&lt;? super A&gt;    -&gt; lowerBound = A, upperBound = any
G&lt;?&gt;            -&gt; lowerBound = null, upperBound = any</code></pre>
</div>
</div>
<div class="paragraph">
<p>This leads to the following expected subtype relations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">(? extends A) &lt;: A  -&gt; true
(? super A) &lt;: A    -&gt; false
A &lt;: (? extends A)  -&gt; false
A &lt;: (? super A)    -&gt; true</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Note that there is a slight difference to Java: In N4JS it is not possible to use a generic type in a raw fashion, that is to say without specifying any type arguments.
In Java, this is possible due to backwards compatibility with early Java versions in which no generics were supported.</p>
</div>
<div class="paragraph">
<p>In case an upper bound of a type variable shall consist only of a few members, it seems convenient to use additional structural members,
like on interface I2 in the example <a href="#ex:use-declared-interfaces-for-lower-bounds">Use declared interfaces for lower bounds</a> below.
However, type variables must not be constrained using structural types (see constraint <a href="classifiers.html#Req-IDE-76">[Req-IDE-76]</a>).
Hence, the recommended solution is to use an explicitly declared interface that uses definition site structural typing for these constraints as an upper bound (see interface in <a href="#ex:use-declared-interfaces-for-lower-bounds">Use declared interfaces for lower bounds</a>).</p>
</div>
<div id="ex:use-declared-interfaces-for-lower-bounds" class="exampleblock">
<div class="title">Example 16. Use declared interfaces for lower bounds</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">interface I1&lt;T extends any with {prop : int}&gt; { // error
}

interface ~J {
    prop : int;
}
interface I2&lt;T extends J&gt; {
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_primitive-ecmascript-types"><a class="anchor" href="#_primitive-ecmascript-types"></a><a class="link" href="#_primitive-ecmascript-types">4.5. Primitive ECMAScript Types</a></h3>
<div class="paragraph">
<p>N4JS provides the same basic types as ECMAScript [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.28)</a>].</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
In ECMAScript, basic types come in two flavors: as primitive types [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8Types, p.p.28)</a>] and as Objects [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S15, p.p.102)</a>].
In N4JS, primitive types are written with lower cases, object types with first case capitalized.
For example, <code>String</code> is the primitive ECMAScript string type, while <code>String</code> is an object.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The following ECMAScript primitive types are supported, they are written
with lower case letters::</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>undefined</code>: [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.3)</a>]; cannot be used in type expression, see void below.</p>
</li>
<li>
<p><code>null</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.3)</a>]; cannot be used in type expression</p>
</li>
<li>
<p><code>boolean</code>  [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.3)</a>]</p>
</li>
<li>
<p><code>string</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.4)</a>]</p>
</li>
<li>
<p><code>number</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.5)</a>]</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Although Object is a primitive type in [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.5)</a>], it is interpreted here as an object type and described in <a href="#_object-type">Object Type</a>.</p>
</div>
<div class="paragraph">
<p>Please note that primitive types are values (= no objects) so they have no properties and you cannot inherit from them.</p>
</div>
<div class="sect3">
<h4 id="_undefined-type"><a class="anchor" href="#_undefined-type"></a><a class="link" href="#_undefined-type">4.5.1. Undefined Type</a></h4>
<div class="paragraph">
<p>As a built-in type, the type <code>undefined</code> cannot be declared explicitly by the user by means of a type expression.
Note in ECMAScript there are three distinct use cases of <code>undefined</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>undefined</code> as type (as used here)</p>
</li>
<li>
<p><code>undefined</code> as value (the only value of the undefined type)</p>
</li>
<li>
<p><code>undefined</code> is a property of the global object with undefined (value) as initial value.
Since ECMAScript 5 it is not allowed to reassign this property but this is not enforced by all ECMAScript/JavaScript engines.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The type <code>undefined</code> will be inferred to false in a boolean expression.
It is important to note that something that is not assigned to a value is <code>undefined</code> but not <code>null</code>.</p>
</div>
<div class="paragraph">
<p>The type <code>undefined</code> is a subtype of all types. That is,</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>undefined</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>is an axiom and true for all types <em>T</em>.</p>
</div>
<div class="paragraph">
<p>Whenever an expression <em>E</em> has an inferred type of <code>undefined</code>, which means it will always evaluate to
value <code>undefined</code> at runtime, a warning is shown, unless <em>E</em> is &#8230;&#8203;</p>
</div>
<div class="ulist">
<ul>
<li>
<p>a <code>void</code> expression</p>
</li>
<li>
<p>the direct child expression of a <code>void</code> expression,</p>
</li>
<li>
<p>the direct child expression of an expression statement,</p>
</li>
<li>
<p>the <code>undefined</code> literal (i.e. the literal representing the <code>undefined</code> value),</p>
</li>
<li>
<p>the <code>this</code> literal.</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_null-type"><a class="anchor" href="#_null-type"></a><a class="link" href="#_null-type">4.5.2. Null Type</a></h4>
<div class="paragraph">
<p>The <code>null</code> type cannot be declared explicitly by the user. Only the keyword <code>null</code> is inferred to type <code>null</code>.</p>
</div>
<h5 id="null-type-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>In contrast to <code>undefined</code>, it expresses the intentional absence of a value.</p>
</div>
<div class="paragraph">
<p>The <code>null</code> type can be assigned to any other type.
That is, the type <code>null</code> is a subtype of all other types except <code>undefined</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi><mo>≠</mo><mstyle mathvariant="monospace"><mtext>undefined</mtext></mstyle></mrow><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>null</mtext></mstyle><mi> </mi><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>Type</mtext></mstyle><mi>r</mi><mi>i</mi><mi>g</mi><mi>h</mi><mi>t</mi></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>Please note that</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>null==undefined</code> evaluates to <code>true</code></p>
</li>
<li>
<p><code>null===undefined</code> evaluates to <code>false</code></p>
</li>
<li>
<p><code>typeof null</code> evaluates to <code>object</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Only the <code>null</code> keyword is inferred to type null. If <code>null</code> is assigned to a variable, the type of the variable is not changed.
This is true, in particular, for variable declarations.
For example in</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var x = null;</code></pre>
</div>
</div>
<div class="paragraph">
<p>the type of variable <code>x</code> is inferred to <code>any</code> (cf. <a href="statements.html#_variable-statement">Variable Statement</a>).</p>
</div>
<div class="paragraph">
<p>The type <code>null</code> will be inferred to false in a boolean expression.</p>
</div>
<div class="paragraph">
<p>The call <code>typeof null</code> will return ’object’.</p>
</div>
</div>
<div class="sect3">
<h4 id="_primitive-boolean-type"><a class="anchor" href="#_primitive-boolean-type"></a><a class="link" href="#_primitive-boolean-type">4.5.3. Primitive Boolean Type</a></h4>
<div class="paragraph">
<p>Represents a logical entity having two values, true and false.</p>
</div>
<div class="paragraph">
<p>Please note that a boolean primitive is coerced to a number in a comparison operation so that</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 66.6666%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-center valign-top">Source</th>
<th class="tableblock halign-center valign-middle">Result</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div><div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var a = true; console.log(a == 1)</code></pre>
</div>
</div></div></td>
<th class="tableblock halign-center valign-middle"><p class="tableblock">prints true</p></th>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div><div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var b = false; console.log(b == 0)</code></pre>
</div>
</div></div></td>
<th class="tableblock halign-center valign-middle"><p class="tableblock">prints true</p></th>
</tr>
</tbody>
</table>
<h5 id="primitive-boolean-type-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>The type <code>boolean</code> is subtype of <code>any</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>boolean</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle></mrow></mfrac><mrow/></math>
</div>
</div>
<div class="paragraph">
<p>Variables of type <code>boolean</code> can be auto-converted (coerced) to <code>Boolean</code>, as described in <a href="conversions_and_reflection.html#_autoboxing-and-coercing">Autoboxing and Coercing</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_primitive-string-type"><a class="anchor" href="#_primitive-string-type"></a><a class="link" href="#_primitive-string-type">4.5.4. Primitive String Type</a></h4>
<div class="paragraph">
<p>A finite sequence of zero or more 16-bit unsigned integer values (elements).
Each element is considered to be a single UTF-16 code unit.</p>
</div>
<div class="paragraph">
<p>Also string as primitive type has no properties, you can access the properties available on the object String as string will be coerced to String on the fly
but just for that property call, the original variable keeps its type:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var a = "MyString"
console.log(typeof a) // string
console.log(a.length) // 8
console.log(typeof a) // string</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can handle a primitive <code>string</code> like an object type <code>String</code> but with these exceptions:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>typeof "MyString"</code> is <code>'string'</code> but <code>typeof new String("MyString")</code> is <code>'object'</code></p>
</li>
<li>
<p><code>"MyString" instanceof String</code> or <code>instanceof Object</code> will return <code>false</code>, for <code>new String("MyString")</code> both checks evaluate to <code>true</code></p>
</li>
<li>
<p><code>console.log(eval("2+2"))</code> returns <code>4</code>, <code>console.log(eval(new String("2+2")))</code> returns string <code>"2+2"</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>This marks a difference to Java.
In JavaScript, Unicode escape sequences are never interpreted as a special character.</p>
</div>
<h5 id="primitive-string-type-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>The <code>string</code> type is a subtype of <code>any</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle></mrow></mfrac><mrow/></math>
</div>
</div>
<div class="paragraph">
<p>It is supertype of the N4JS primitive type <code>pathselector</code>, <code>typeName</code> and <code>i18nKey</code>.
<a href="#_primitive-pathselector-and-i18nkey">Primitive Pathselector and I18nKey</a></p>
</div>
<div class="paragraph">
<p>However, variables of type <code>string</code> can be auto-converted (coerced) to <code>string</code>, as described in <a href="conversions_and_reflection.html#_autoboxing-and-coercing">Autoboxing and Coercing</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_primitive-number-type"><a class="anchor" href="#_primitive-number-type"></a><a class="link" href="#_primitive-number-type">4.5.5. Primitive Number Type</a></h4>
<div class="paragraph">
<p>In ECMAScript numbers are usually 64-bit floating point numbers.
For details see [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.8.5)</a>].
The prefix <code>0</code> indicates that the number is octal-based and the prefix <code>0x</code> marks it as hexadecimal-based.</p>
</div>
<div class="paragraph">
<p><code>NaN</code> can be produced by e.g. &#8216;0 / 0&#8217;' or &#8216;1 - x&#8217;. <code>typeof NaN</code> will return <code>number</code>.</p>
</div>
<h5 id="primitive-number-type-semantics" class="discrete">Semantics</h5>
<div class="paragraph">
<p>The type <code>number</code> is subtype of <code>any</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>number</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>any</mtext></mstyle></mrow></mfrac><mrow/></math>
</div>
</div>
<div class="paragraph">
<p>However, variables of type <code>number</code> can be auto-converted (coerced) to <code>Number</code>, as described in <a href="expressions.html#_integer-literals">Integer Literals</a> .</p>
</div>
</div>
<div class="sect3">
<h4 id="_primitive-type-int"><a class="anchor" href="#_primitive-type-int"></a><a class="link" href="#_primitive-type-int">4.5.6. Primitive Type int</a></h4>
<div class="paragraph">
<p>Actually ECMAScript defines an internal type <code>int32</code>.
A number of this type is returned by the binary or operation using zero as operand, e.g. ECMAScript’s internal type int32 can be represented in N4JS by a built-in primitive type called <code>int</code>.
For details on how numeric literals map to types <code>number</code> and <code>int</code>, refer to <a href="expressions.html#_integer-literals">Integer Literals</a>.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title=""></i>
</td>
<td class="content">
for the time being, built-in type <code>int</code> is synonymous to type <code>number</code>.
This means one can be assigned to the other and a value declared to be of type <code>int</code> may actually be a 64-bit floating
point number.<sup class="footnote">[<a id="_footnoteref_14" class="footnote" href="appendix_c_bibliography.html#_footnote_14" title="View footnote.">14</a>]</sup>
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="_primitive-symbol-type"><a class="anchor" href="#_primitive-symbol-type"></a><a class="link" href="#_primitive-symbol-type">4.5.7. Primitive Symbol Type</a></h4>
<div class="paragraph">
<p>The primitive type <code>symbol</code> is directly as in ECMAScript 6.
Support for symbols is kept to a minimum in N4JS. While this primitive type can be used without any restrictions, the only value of this type available in N4JS is the built-in symbol <code>Symbol.iterator</code>.
Other built-in symbols from ECMAScript 6 and the creation of new symbols are not supported.
For more details, see <a href="#_symbol">Symbol</a>.</p>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_primitive-n4js-types"><a class="anchor" href="#_primitive-n4js-types"></a><a class="link" href="#_primitive-n4js-types">4.6. Primitive N4JS Types</a></h3>
<div class="paragraph">
<p>Additionally to the primitive ECMAScript types, the following N4JS-specific primitive types are supported:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>any</code></dt>
<dd>
<p>enables ECMAScript-like untyped variable declarations</p>
</dd>
<dt class="hdlist1"><code>void</code></dt>
<dd>
<p>almost similar to undefined, except it can be used as a return type of functions and methods</p>
</dd>
<dt class="hdlist1"><code>unknown</code></dt>
<dd>
<p>inferred in case of a type inference error</p>
</dd>
<dt class="hdlist1"><code>pathSelector&lt;T&gt;</code>, <code>i18nKey</code></dt>
<dd>
<p>subtypes of string</p>
</dd>
</dl>
</div>
<div class="sect3">
<h4 id="_any-type"><a class="anchor" href="#_any-type"></a><a class="link" href="#_any-type">4.6.1. Any Type</a></h4>
<div class="paragraph">
<p>Any type is the default type of all variables for without a type declaration.
It has no properties.
A value of any other type can be assigned to a variable of type <code>any</code>, but a variable declared <code>any</code> can only be assigned to another variable declared with the type <code>any</code>.</p>
</div>
<div class="sect4">
<h5 id="any-type-semantics"><a class="anchor" href="#any-type-semantics"></a><a class="link" href="#any-type-semantics">4.6.1.1. Semantics</a></h5>
<div class="paragraph">
<p><code>any</code> is supertype of all other types. That is,</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>Type</mtext></mstyle><mi>l</mi><mi>e</mi><mi>f</mi><mi>t</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mrow><mi>a</mi><mi>n</mi><mi>y</mi></mrow></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>is an axiom and true for all types.</p>
</div>
</div>
<div class="sect4">
<h5 id="any-type-type-inference"><a class="anchor" href="#any-type-type-inference"></a><a class="link" href="#any-type-type-inference">4.6.1.2. Type Inference</a></h5>
<div class="paragraph">
<p>If a variable is explicitly declared as type <code>any</code>, the inferred type of that variable will always be <code>any</code>.</p>
</div>
<div class="sect5">
<h6 id="_default-type-of-variables"><a class="anchor" href="#_default-type-of-variables"></a><a class="link" href="#_default-type-of-variables">4.6.1.2.1. Default Type of Variables</a></h6>
<div class="paragraph">
<p>If a type annotation is missing and no initializer is provided, then the type of a variable is implicitly set to <code>any</code>.</p>
</div>
<div class="paragraph">
<p>In that case, the inferred type of that variable will always be <code>any</code> as well.
If an initializer is provided, the declared type of the variable will be set to the inferred type of the initializer.
Therefore in the latter case, the inferred type of the variable will always be the type of the initializer (cf. <a href="statements.html#_variable-statement">Variable Statement</a>).</p>
</div>
<div class="paragraph">
<p>If a variable is declared as type , it can be used just as every variable can be used in raw ECMAScript.
Since every property can be get and set, the types of properties is inferred as as well.
This is formally expressed in <a href="expressions.html#_identifier">Identifier</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_void-type"><a class="anchor" href="#_void-type"></a><a class="link" href="#_void-type">4.6.2. Void Type</a></h4>
<div class="paragraph">
<p>The type <code>void</code> is used to denote that there is no value at all, as opposed to type
<code>undefined</code> which denotes that there is a value, but it is always undefined.</p>
</div>
<div class="paragraph">
<p>The only valid use of type <code>void</code> is to declare that a function or method does not
return anything. In particular, this means:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>void</code> is disallowed as type argument,</p>
</li>
<li>
<p><code>void</code> is disallowed as upper/lower bound of type parameters and wild cards,</p>
</li>
<li>
<p>when used as return type of functions or methods, <code>void</code> may not be nested, i.e.</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">function foo(): void {}  // ok
function bar(): any|void {}  // error</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>In all the above disallowed cases, type <code>undefined</code> should be used instead of <code>void</code>.</p>
</div>
<div class="sect4">
<h5 id="void-type-semantics"><a class="anchor" href="#void-type-semantics"></a><a class="link" href="#void-type-semantics">4.6.2.1. Semantics</a></h5>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-13"></a><strong>Req. IDE-13:</strong> <a href="#Req-IDE-13">Void Type</a> (ver. 1)</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The type <code>void</code> may only be used as the immediate return type of a function or method.</p>
</li>
<li>
<p>If a function <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi></math> is declared to return <code>void</code>, an error is created if a return statement contains an expression:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi><mo>.</mo><mi>r</mi><mi>e</mi><mi>t</mi><mi>u</mi><mi>r</mi><mi>n</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>void</mtext></mstyle><mo>→</mo></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>r</mi><mo>,</mo><mi>μ</mi><mfenced close=")" open="("><mi>r</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>ReturnStatement</mtext></mstyle><mo>,</mo><mi>r</mi><mo>.</mo><mi>c</mi><mi>o</mi><mi>n</mi><mi>t</mi><mi>a</mi><mi>i</mi><mi>n</mi><mi>i</mi><mi>n</mi><mi>g</mi><mi>F</mi><mi>u</mi><mi>n</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>=</mo><mi>f</mi><mi>:</mi><mi>r</mi><mo>.</mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>null</mtext></mstyle></math></p>
</div>
</li>
<li>
<p>If a function <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi></math> is declared to return <code>void</code>, an error is issued if the function is called in any statement or expression but an expression statement directly:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi><mo>.</mo><mi>r</mi><mi>e</mi><mi>t</mi><mi>u</mi><mi>r</mi><mi>n</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>void</mtext></mstyle><mo>→</mo></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>e</mi><mo>,</mo><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mfenced close=")" open="("><mi>e</mi><mi>f</mi></mfenced><mi>:</mi><mi>μ</mi><mfenced close=")" open="("><mrow><mi>e</mi><mo>.</mo><mi>c</mi><mi>o</mi><mi>n</mi><mi>t</mi><mi>a</mi><mi>i</mi><mi>n</mi><mi>e</mi><mi>r</mi></mrow></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>ExpressionStatement</mtext></mstyle></math></p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>The following type hierarchy is defined: <code>void</code> is only a subtype of itself but not of any other type and no other type is a subtype of void.</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>void</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>void</mtext></mstyle></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>Since <code>void</code> cannot be used as the type of variables, fields, formal parameters, etc., a
function or method with a return type of void cannot be used on the right-hand side of
an assignment or in the argument list of a call expression (note the difference to plain
JavaScript).</p>
</div>
<div class="paragraph">
<p>The ECMAScript <code>void</code> operator (see <a href="expressions.html#_unary-expression">Unary Expressions</a>) has a type
of <code>undefined</code>, not <code>void</code>, because it evaluates to value <code>undefined</code> and can be used
on the right-hand side of assignments, etc.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_unknown-type"><a class="anchor" href="#_unknown-type"></a><a class="link" href="#_unknown-type">4.6.3. Unknown Type</a></h4>
<div class="paragraph">
<p>Internally N4JS defines the type <code>unknown</code>.
This type cannot be used by the user.
Instead, it is inferred in case of errors.
<code>unknown</code> behaves almost similar to <code>any+</code>.
However no error messages once a variable or expression has been inferred to <code>unknown</code> in order to avoid consequential errors.</p>
</div>
</div>
<div class="sect3">
<h4 id="_primitive-pathselector-and-i18nkey"><a class="anchor" href="#_primitive-pathselector-and-i18nkey"></a><a class="link" href="#_primitive-pathselector-and-i18nkey">4.6.4. Primitive Pathselector and I18nKey</a></h4>
<div class="paragraph">
<p>N4JS introduces three new types which are subtypes of string.
These types are, in fact, translated to strings and do not add any new functionality.
They are solely defined for enabling additional validation.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>pathSelector&lt;T&gt;</code> is a generic type for specifying path selector expressions. PathSelectors are used to specify a path to a property in a (JSON-like) model tree.</p>
</li>
<li>
<p>The type variable <code>T</code> defines the context type (or type of the root of the tree) in which the selector is to be validated.
A path selector is defined as a string literal that has to conform to the path selector grammar.
The context type is then used to perform a semantic</p>
</li>
<li>
<p><code>i18nKey</code> is a string which refers to an internationalization key.
The <code>i18nKey</code> type is used to reference resource keys specified in resource files.
In a project <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi></math>, the <code>i18nKey</code> type defines the transitive set of all resource keys accessible from <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi></math>.
Since resource keys are specified as strings, this means that the <code>i18nKey</code> type defines a subset of all string literals that can be assigned to a variable of type <code>i18nKey</code> in the current project.
That means that an assignment of a string literal to a variable of type <code>i18nKey</code> is only valid if that string literal is contained in the set defined by <code>i18nKey</code>.
Resource keys are declared in the properties files of a project and all resource keys from a project are accessible to any project depending on it.</p>
</li>
</ul>
</div>
<div class="paragraph todo">
<p>I18nkeys are not yet validated</p>
</div>
<div class="sect4">
<h5 id="pathselector-semantics"><a class="anchor" href="#pathselector-semantics"></a><a class="link" href="#pathselector-semantics">4.6.4.1. Semantics</a></h5>
<div class="paragraph">
<p>The N4JS primitive types <code>pathSelector&lt;T&gt;</code>, <code>i18nKey</code> and <code>pathSelector&lt;T&gt;</code> are basically only marker types of strings for enabling additional validation.
Thus, they are completely interchangeable with string types:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>typeName</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mo>&gt;</mo><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac><mspace width="3.0mm"/><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>typeName</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mo>&gt;</mo></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>i18nKey</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac><mspace width="3.0mm"/><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>i18nKey</mtext></mstyle></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>pathSelector</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mo>&gt;</mo><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac><mspace width="3.0mm"/><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>pathSelector</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mo>&gt;</mo></mrow></mfrac></math></p>
</div>
<div class="paragraph">
<p>As special literals for these N4JS types do not exist, the type has to be explicitly specified in order to enable the additional validation.
Note that this validation cannot be applied for more complicated expressions with parts which cannot be evaluated at compile time.
For example, <code>"some.path."segment".prop"</code> cannot be evaluated at compile time.</p>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_built-in-ecmascript-object-types"><a class="anchor" href="#_built-in-ecmascript-object-types"></a><a class="link" href="#_built-in-ecmascript-object-types">4.7. Built-in ECMAScript Object Types</a></h3>
<div class="paragraph">
<p>N4JS supports all built-in ECMAScript objects [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S15)</a>], interpreted as classes.
Some of these object types are object versions of primitive types.
The object types have the same name as their corresponding primitive type, but start with an upper case letter.</p>
</div>
<div class="paragraph">
<p>The following types, derived from certain ECMAScript predefined objects and constructs, are supported by means of built-in types as they are required by certain expressions.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>Object</code>   [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.111)</a>];</p>
</li>
<li>
<p><code>Function</code>  [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.117)</a>]; representing functions and function objects <a href="functions.html#_function-type">Function Type</a> but also methods (<a href="classifiers.html#_methods">Methods</a>)</p>
</li>
<li>
<p><code>Array</code>    [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.122)</a>], representing array objects, see <a href="#_array-object-type">Array Object Type</a></p>
</li>
<li>
<p><code>String</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.141)</a>]</p>
</li>
<li>
<p><code>Boolean</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.141)</a>]</p>
</li>
<li>
<p><code>Number</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.141)</a>]</p>
</li>
<li>
<p><code>RegExp</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.p.180)</a>]; they can be constructed by means of special literals (cf. <a href="expressions.html#_literals">Literals</a>)</p>
</li>
<li>
<p>global object type</p>
</li>
<li>
<p><code>Symbol</code></p>
</li>
<li>
<p><code>Promise</code></p>
</li>
<li>
<p><code>Iterator</code> and <code>Iterable</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>All other ECMAScript types ([<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S15)</a>], such as <code>Math</code>, <code>Date</code>, or <code>Error</code> are supported by means of predefined classes.
ECMAScript 2015 types are defined in the ECMAScript 2015 runtime environment.
Since they are defined and used similar to user defined classes, they are not explained in further detail here.
These predefined objects are kind of subtypes of <code>Object</code>.</p>
</div>
<div class="sect3">
<h4 id="ECMAScript-objects-semantics"><a class="anchor" href="#ECMAScript-objects-semantics"></a><a class="link" href="#ECMAScript-objects-semantics">4.7.1. Semantics</a></h4>
<div class="paragraph">
<p>It is not possible to inherit from any of the built-in ECMAScript object types except for <code>Object</code> and <code>Error</code>, that is,
to use one of these types as supertype of a class.
From the N4JS language’s point of view, these built-in types are all final.</p>
</div>
</div>
<div class="sect3">
<h4 id="_object-type"><a class="anchor" href="#_object-type"></a><a class="link" href="#_object-type">4.7.2. Object Type</a></h4>
<div class="paragraph">
<p><code>Object</code> [<a href="appendix_c_bibliography.html#ECMA11a">ECMA11a(p.S8.6)</a>] is the (implicit) supertype of all declared (i.e., non-primtive) types, including native types.
It models the ECMAScript type <code>Object</code>, except that no properties may be dynamically added to it.
In order to declare a variable to which properties can be dynamically added, the type <code>Object+</code> has to be declared
(cf. <a href="#_type-modifiers">Type Modifiers</a>).</p>
</div>
</div>
<div class="sect3">
<h4 id="_function-object-type"><a class="anchor" href="#_function-object-type"></a><a class="link" href="#_function-object-type">4.7.3. Function-Object-Type</a></h4>
<div class="paragraph">
<p>The built-in object type <code>Function</code>, a subtype of <code>Object</code>, represents all functions, regardless of how they are defined (either via function expression,
function declaration, or method declaration).
They are described in detail in <a href="#_function-object-type">Function-Object-Type</a>.</p>
</div>
<div class="paragraph">
<p>Since <code>Function</code> is the supertype of all functions regardless of number and types of formal parameters, return type, and number and bounds of type parameters,
it would not normally be possible to invoke an instance of <code>Function</code>.
For the time being, however, an instance of <code>Function</code> can be invoked, any number of arguments may be provided and the invocation may be parameterized with any number of
type arguments (which will be ignored), i.e.  <a href="expressions.html#Req-IDE-101">[Req-IDE-101]</a> and <a href="expressions.html#Req-IDE-102">[Req-IDE-102]</a> do not apply.</p>
</div>
</div>
<div class="sect3">
<h4 id="_array-object-type"><a class="anchor" href="#_array-object-type"></a><a class="link" href="#_array-object-type">4.7.4. Array Object Type</a></h4>
<div class="paragraph">
<p>The <code>Array</code> type is generic with one type parameter, which is the item type. An array is accessed with the index operator, the type of the index parameter is <code>Number</code>.
The type of the stored values is <em>typeArgs[0]</em> (cf. <a href="expressions.html#_array-literal">Array Literal</a>). Due to type erasure, the item type is not available during runtime,
that is to say there are no reflective methods returning the item type of an array.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-14"></a><strong>Req. IDE-14:</strong> <a href="#Req-IDE-14">Array Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For an array type <em>A</em>, the following conditions must be true:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>|</mo><mi>A</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>A</mi><mi>r</mi><mi>g</mi><mi>s</mi><mo>|</mo><mo>=</mo><mn>1</mn></math></p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_string-object-type"><a class="anchor" href="#_string-object-type"></a><a class="link" href="#_string-object-type">4.7.5. String Object Type</a></h4>
<div class="paragraph">
<p>Object type version of <code>string</code>. It is highly recommend to use the primitive version only.
Note that is is not possible to assign a primitive typed value to an object typed variable.</p>
</div>
</div>
<div class="sect3">
<h4 id="_boolean-object-type"><a class="anchor" href="#_boolean-object-type"></a><a class="link" href="#_boolean-object-type">4.7.6. Boolean Object Type</a></h4>
<div class="paragraph">
<p>Object type version of <code>boolean</code>. It is highly recommend to use the primitive version only.
Note that is is not possible to assign a primitive typed value to an object typed variable.</p>
</div>
</div>
<div class="sect3">
<h4 id="_number-object-type"><a class="anchor" href="#_number-object-type"></a><a class="link" href="#_number-object-type">4.7.7. Number Object Type</a></h4>
<div class="paragraph">
<p>Object type version of <code>number</code>. It is highly recommend to use the primitive version only.
Note that is is not possible to assign a primitive typed value to an object typed variable.</p>
</div>
</div>
<div class="sect3">
<h4 id="_global-object-type"><a class="anchor" href="#_global-object-type"></a><a class="link" href="#_global-object-type">4.7.8. Global Object Type</a></h4>
<div class="paragraph">
<p>This is the globally accessible namespace which contains element such as undefined, and in case of browsers, window. Depending on the runtime environment,
the global object may has different properties defined by means of dynamic polyfills.</p>
</div>
</div>
<div class="sect3">
<h4 id="_symbol"><a class="anchor" href="#_symbol"></a><a class="link" href="#_symbol">4.7.9. Symbol</a></h4>
<div class="paragraph">
<p>The symbol constructor function of ECMAScript 2015. Support for symbols
is kept to a minimum in N4JS:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>creating symbols with <code>var sym = Symbol("description")</code> is not supported.</p>
</li>
<li>
<p>creating shared symbols with <code>var sym = Symbol.for("key")</code> is not supported.
Also the inverse <code>Symbol.keyFor(sym)</code> is not supported.</p>
</li>
<li>
<p>retrieving built-in symbols via properties in <code>Symbol</code> is supported, however, the only built-in symbol available in N4JS is the iterator symbol that can be retrieved with <code>Symbol.iterator</code>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The rationale for this selective support for symbols in N4JS is to allow for the use (and custom definition) of iterators and iterables and their application in the <code>for&#8230;&#8203;of</code>
loop with as little support for symbols as possible.</p>
</div>
</div>
<div class="sect3">
<h4 id="_promise"><a class="anchor" href="#_promise"></a><a class="link" href="#_promise">4.7.10. Promise</a></h4>
<div class="paragraph">
<p><code>Promise</code> is provided as a built-in type as in ECMAScript 2015.
Also see <a href="functions.html#_asynchronous-functions">Asynchronous Functions</a> for asynchronous functions.</p>
</div>
</div>
<div class="sect3">
<h4 id="_iterator-interface"><a class="anchor" href="#_iterator-interface"></a><a class="link" href="#_iterator-interface">4.7.11. Iterator Interface</a></h4>
<div class="paragraph">
<p>A structurally typed interface for <em>iterators</em> as defined by theECMAScript 6 iterator protocol.</p>
</div>
<div class="listingblock">
<div class="title">Iterable in N4JS</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">// providedByRuntime
export public interface ~Iterator&lt;T&gt;  {
    public next(): IteratorEntry&lt;T&gt;
}

// providedByRuntime
export public interface ~IteratorEntry&lt;T&gt; {
    public done: boolean;
    public value: T?;
}</code></pre>
</div>
</div>
<div class="paragraph todo">
<p>Interface <code>IteratorEntry</code> was introduced mainly as a workaround; this interface could be removed and replaced with a corresponding
structural type reference as return type of method <code>next()</code></p>
</div>
</div>
<div class="sect3">
<h4 id="_iterable-interface"><a class="anchor" href="#_iterable-interface"></a><a class="link" href="#_iterable-interface">4.7.12. Iterable Interface</a></h4>
<div class="paragraph">
<p>A structurally typed interface for objects that can be iterated over, i.e. <em>iterables</em> as defined by the ECMAScript 6 iterator protocol.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">// providedByRuntime
export public interface ~Iterable&lt;T&gt; {
    public [Symbol.iterator](): Iterator&lt;T&gt;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that this interface’s method is special in that a symbol is used as identifier.
You can use the ordinary syntax for computed property names in ECMAScript 6 for overriding / implementing or invoking this method.</p>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_built-in-n4js-types"><a class="anchor" href="#_built-in-n4js-types"></a><a class="link" href="#_built-in-n4js-types">4.8. Built-In N4JS Types</a></h3>
<div class="paragraph">
<p>N4JS additionally provides some built-in classes which are always available with the need to explicitly import them.</p>
</div>
<div class="sect3">
<h4 id="_n4object"><a class="anchor" href="#_n4object"></a><a class="link" href="#_n4object">4.8.1. N4Object</a></h4>
<div class="paragraph">
<p>Although <code>N4Object</code> is a built-in type, it is not the default supertype.
It is a subtype of <code>Object</code>.</p>
</div>
<div class="sect4">
<h5 id="N4Object-semantics"><a class="anchor" href="#N4Object-semantics"></a><a class="link" href="#N4Object-semantics">4.8.1.1. Semantics</a></h5>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>N4Object</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>Object</mtext></mstyle></mrow></mfrac></math>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_n4class"><a class="anchor" href="#_n4class"></a><a class="link" href="#_n4class">4.8.2. N4Class</a></h4>
<div class="paragraph">
<p>The type <code>N4Class</code> is used for extended reflection in N4JS.</p>
</div>
<div class="paragraph todo">
<p>Add further docs for this type</p>
</div>
</div>
<div class="sect3">
<h4 id="IterableN"><a class="anchor" href="#IterableN"></a><a class="link" href="#IterableN">4.8.3. IterableN</a></h4>
<div class="paragraph todo">
<p>Work in progress.</p>
</div>
<div class="paragraph">
<p>Currently there are built-in types <code>Iterable2&lt;T1,T2&gt;</code>&#8230;&#8203;<code>Iterable9&lt;T1,&#8230;&#8203;,T9&gt;</code>.
They are mainly intended for type system support of array destructuring literals.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
This is not documented in detail yet, because we want to gain experience with the current solution first, major refinement may be incoming.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_type-modifiers"><a class="anchor" href="#_type-modifiers"></a><a class="link" href="#_type-modifiers">4.9. Type Modifiers</a></h3>
<div class="paragraph">
<p>Type expressions can be further described with type modifiers.
The type modifiers add additional constraints to the type expression which are then used to perform a stricter validation of the source code.
Type modifiers can not be used in type arguments.</p>
</div>
<div class="paragraph">
<p>The general type modifiers <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><mi>o</mi><mi>n</mi><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>y</mi><mi>n</mi><mi>a</mi><mi>m</mi><mi>i</mi><mi>c</mi></math> can be used for variables, attributes, method parameters and method types.
Optional and variadic modifiers can only be applied for formal parameters.</p>
</div>
<div class="sect3">
<h4 id="Type_Modifiers_Dynamic"><a class="anchor" href="#Type_Modifiers_Dynamic"></a><a class="link" href="#Type_Modifiers_Dynamic">4.9.1. Dynamic</a></h4>
<div class="paragraph">
<p>The dynamic type modifier marks a type as being dynamic.
A dynamic type behaves like a normal JavaScript object, so you can read/write any property and call any method on it.
The default behavior for a type is to be static, that is no new properties can be added and no unknown properties can be accessed.</p>
</div>
<div class="paragraph">
<p><code>T</code> <math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/></math> <code>T+</code> and <code>T+</code> <math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/></math> <code>T</code> is always true.
Using dynamically added members of a dynamic type is never type safe.
Using the <code>delete</code> operator on a subtype of <code>N4Object</code> is not allowed.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-15"></a><strong>Req. IDE-15:</strong> <a href="#Req-IDE-15">Non-Dynamic Primitive Types</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>All primitive types except <code>any</code> must not be declared dynamic.</p>
</li>
<li>
<p>Only parameterized type references and this type reference can be declared dynamic.<sup class="footnote">[<a id="_footnoteref_15" class="footnote" href="appendix_c_bibliography.html#_footnote_15" title="View footnote.">15</a>]</sup></p>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_optional-return-types"><a class="anchor" href="#_optional-return-types"></a><a class="link" href="#_optional-return-types">4.9.2. Optional Return Types</a></h4>
<div class="paragraph">
<p>Only formal parameters and return types can be marked as optional.</p>
</div>
<div class="paragraph">
<p>An optional return type indicates that the function / method need not be left via a return statement with an expression; in that case the return value is <code>undefined</code>.
For constraints on using the optional modifier, see <a href="#_function-object-type">Function-Object-Type</a>.</p>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_union-and-intersection-type-composed-types"><a class="anchor" href="#_union-and-intersection-type-composed-types"></a><a class="link" href="#_union-and-intersection-type-composed-types">4.10. Union and Intersection Type (Composed Types)</a></h3>
<div class="paragraph">
<p>Given two or more existing types, it is possible to compose a new type by forming either the union or intersection of the base types.
The following example gives a small overview of common use cases of union and intersection types.</p>
</div>
<div class="exampleblock">
<div class="title">Example 17. Composed types</div>
<div class="content">
<div class="paragraph">
<p>This example shows how union and intersection types affect the types of their field members in case the fields have different types.
It is for illustration purposes only.
The type of the composed field depends on the access type:
When reading, the field type of an intersection/union also resolves to the intersection/union.
In contrast, when writing a field, the field type of an intersection/union resolves to the union/intersection respectively.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">interface A { f : int = 1; }
interface B { f : string = "h"; }

class CA implements A {}
class CB implements B {}

let aub : A|B; // union type
let aib : A&amp;B; // intersection type

function u() {
    aub = (catIsAlive)? new CA() : new CB(); // catIsAlive is boolean
    let x = aub.f; // x = {1 | "h"}
    aub.f = undefined; // undefined can be assigned to int and string types
}
function i() {
    let a = aib as A;
    let b = aib as B;
    a.f = 23;
    b.f = "text";
    let x = aib.f; // x = {23 &amp; "text"} which is impossible
}
// type of 'aub.f' --&gt; int|string
let fu = aub.f;
// type of 'aub.f' --&gt; int&amp;string
aub.f = undefined;
// type of 'aib.f' --&gt; int&amp;string
let fi = aib.f;
// type of 'aib.f' --&gt; int|string
aib.f = undefined;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that no instance <code>aib</code> of intersection type <code>A&amp;B</code> can be instantiated, since the instance&#8217;s class would have to define a field <code>f</code> which would have to comply to both of the interfaces <code>A</code> and <code>B</code>.
Still the function <code>i()</code> shows in general how variables of intersection types can be casted and accessed.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>The following sections define these <em>union</em> and <em>intersection types</em> in detail.</p>
</div>
<div class="sect3">
<h4 id="_union-type"><a class="anchor" href="#_union-type"></a><a class="link" href="#_union-type">4.10.1. Union Type</a></h4>
<div class="paragraph">
<p>Union type reflect the dynamic nature of JavaScript. Union types can be used almost everywhere (e.g., in variable declarations or in formal method parameters).
The type inferencer usually avoids returning union types and prefers single typed joins or meets.
<em>The most common use case for union types is for emulating method overloading</em>, as
we describe later on.<sup class="footnote">[<a id="_footnoteref_16" class="footnote" href="appendix_c_bibliography.html#_footnote_16" title="View footnote.">16</a>]</sup></p>
</div>
<div class="sect4">
<h5 id="union-type-syntax"><a class="anchor" href="#union-type-syntax"></a><a class="link" href="#union-type-syntax">4.10.1.1. Syntax</a></h5>
<div class="paragraph">
<p>For convenience, we repeat the definition of union type expression:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">UnionTypeExpression: 'union' '{' typeRefs+=TypeRefWithoutModifiers (',' typeRefs+=TypeRefWithoutModifiers)* '}';</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="union-type-semantics"><a class="anchor" href="#union-type-semantics"></a><a class="link" href="#union-type-semantics">4.10.1.2. Semantics</a></h5>
<div class="paragraph">
<p>An union type states that the type of a variable may be one or more types contained in the union type.
In other words, a union type is a kind of type set, and the type of a variable is contained in the type set.
Due to interfaces, a variable may conform to multiple types.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-18"></a><strong>Req. IDE-18:</strong> <a href="#Req-IDE-18">Union Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><msub><mi>T</mi><mn>1</mn></msub><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><msub><mi>T</mi><mi>n</mi></msub></mfenced></math>, the following conditions must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Non-empty: At least one element has to be specified:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>≠</mo><mi>∅</mi></math> (<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>n</mi><mo>≥</mo><mn>1</mn><mo>)</mo></mrow></math></p>
</li>
<li>
<p>Non-dynamic: The union type itself must not be declared dynamic:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>¬</mo><mi>U</mi><mo>.</mo><mi>d</mi><mi>y</mi><mi>n</mi><mi>a</mi><mi>m</mi><mi>i</mi><mi>c</mi></math></p>
</li>
<li>
<p>Non-optional elements:<br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>T</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>→</mo><mo>¬</mo><mi>T</mi><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></math></p>
</li>
</ol>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-19"></a><strong>Req. IDE-19:</strong> <a href="#Req-IDE-19">Union Type Subtyping Rules</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Let <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> be an union type.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The union type is a common supertype of all its element types:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>T</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi></mrow><mrow><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>U</mi></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>More generally, a type is a subtype of a union type, if it is a
subtype of at least one type contained in the union:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mo>∃</mo><mi>T</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mi>S</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi></mrow><mrow><mi>S</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>U</mi></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>A union type is a subtype of a type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>S</mi></math>, if all types of the union are subtypes of that type.
This rule is a generalization of the sub typing rules given in [<a href="appendix_c_bibliography.html#Igarashi07a">Igarashi07a(p.p.40)</a>]</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mo>∀</mo><mi>T</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow><mrow><mi>U</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>Commutativity: The order of element does not matter:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>A</mi><mo>,</mo><mi>B</mi></mrow></mfenced><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>B</mi><mo>,</mo><mi>A</mi></mrow></mfenced></math>
</div>
</div>
</li>
<li>
<p>Associativity:
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>A</mi><mo>,</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>B</mi><mo>,</mo><mi>C</mi></mrow></mfenced></mrow></mfenced><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>A</mi><mo>,</mo><mi>B</mi></mrow></mfenced><mo>,</mo><mi>C</mi></mrow></mfenced></math></p>
</li>
<li>
<p>Uniqueness of elements: A union type may not contain duplicates
(similar to sets):</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mn>1</mn><mo>≤</mo><mi>i</mi><mo>&lt;</mo><mi>k</mi><mo>≤</mo><mi>n</mi><mo>,</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mi>:</mi><msub><mi>T</mi><mi>i</mi></msub><mo>≠</mo><msub><mi>T</mi><mi>k</mi></msub></math></p>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-20"></a><strong>Req. IDE-20:</strong> <a href="#Req-IDE-20">Implicit simplification of union types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Let <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> be an union type.
The following simplification rules are always automatically applied to union types.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Simplification of union type with one element:
If a union type contains only one element, it is reduced to the element:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mi>T</mi></mfenced></mrow><mi>T</mi></mfrac></math>
</div>
</div>
</li>
<li>
<p>Simplification of union types of union types:
A union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> containing another union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>V</mi></math> is reduced to a single union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>W</mi></math>, with
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>W</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>=</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>∪</mo><mi>V</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi></math>:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mrow><mi>k</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>,</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>m</mi></msub></mrow></mfenced><mo>,</mo><msub><mi>S</mi><mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>n</mi></msub></mrow></mfenced></mrow><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mrow><mi>k</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>,</mo><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>m</mi></msub><mo>,</mo><msub><mi>S</mi><mrow><mi>k</mi><mo>+</mo><mn>1</mn></mrow></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>n</mi></msub></mrow></mfenced></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>Simplification of union type with undefined or null:
Since undefined is the bottom type, and null is kind of a second button type, they are removed from the union:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mrow><mi>k</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>,</mo><msub><mi>T</mi><mi>k</mi></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mrow><mi>k</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>,</mo><mi>u</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>f</mi><mi>i</mi><mi>n</mi><mi>e</mi><mi>d</mi></mrow></mfenced><mo>,</mo><msub><mi>T</mi><mi>k</mi></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mrow><mi>k</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>,</mo><msub><mi>T</mi><mi>k</mi></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mrow><mi>k</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>,</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mrow></mfenced><mo>,</mo><msub><mi>T</mi><mi>k</mi></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfrac></math></p>
</div>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
Simplification rules for union types with one element are applied first.
</td>
</tr>
</table>
</div>
<div class="ulist">
<ul>
<li>
<p>The structural typing strategy is propagated to the types of the union:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>~</mi><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>~</mi><msub><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mn>1</mn></msub><mo>,</mo><mi>…</mi><mo>,</mo><mi>~</mi><msub><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mi>n</mi></msub></mrow></mfenced></mrow></mfrac></math>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>Remarks:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The simplification rules may be applied recursively.</p>
</li>
<li>
<p>For given types <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math>, and the union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>A</mi><mo>,</mo><mi>B</mi></mrow></mfenced></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>≠</mo><mi>B</mi></math>.
The types are equivalent, however: <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mo>=</mo><mi>U</mi></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mo>=</mo><mi>A</mi></math>.<sup class="footnote">[<a id="_footnoteref_17" class="footnote" href="appendix_c_bibliography.html#_footnote_17" title="View footnote.">17</a>]</sup></p>
</li>
</ul>
</div>
<div class="exampleblock">
<div class="title">Example 18. Subtyping with union type</div>
<div class="content">
<div class="paragraph">
<p>Let A, B, and C be defined as in the chapter beginning (<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>B</mi><mo>&lt;</mo><mi>:</mi><mi>A</mi></math>)</p>
</div>
<div class="paragraph">
<p>The following subtyping relations with union types are to be evaluated as follows: <sup class="footnote">[<a id="_footnoteref_18" class="footnote" href="appendix_c_bibliography.html#_footnote_18" title="View footnote.">18</a>]</sup></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">A &lt;: union{A}                                   -&gt; true
A &lt;: union{A,B}                                 -&gt; true
B &lt;: union{A,B}                                 -&gt; true
C &lt;: union{A,B}                                 -&gt; true
A &lt;: union{B,C}                                 -&gt; false
B &lt;: union{B,C}                                 -&gt; true
C &lt;: union{B,C}                                 -&gt; true
union{A} &lt;: A                                   -&gt; true
union{B} &lt;: A                                   -&gt; true
union{B,C} &lt;: A                                 -&gt; true
union{A,B} &lt;: B                                 -&gt; false
union{X,Z} &lt;: union{Z,X}                        -&gt; true
union{X,Y} &lt;: union{X,Y,Z}                      -&gt; true
union{X,Y,Z} &lt;: union{X,Y}                      -&gt; false</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The simplification constraints are used by the type inferrer.
It may be useful, however, to define union types with superfluous elements, as the next example demonstrates</p>
</div>
<div class="exampleblock">
<div class="title">Example 19. Superfluous elements in union type</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A{}
class B extends A{}
class C extends A{}

function foo(p: union{A,B}) {..}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Although <code>B</code> is superfluous, it may indicate that the function handles parameters of type differently than one of type <code>A</code> or <code>C</code>.</p>
</div>
<div class="paragraph">
<p>Although a union type is a <code><a href="appendix_a_acronyms.html#_acronyms">LCST</a></code> of its contained (non-superfluous) types, the type inferrer usually does not create new union types when computing the join of types.
If the join of types including at least one union type is calculated, the union type is preserved if possible.
The same is true for meet.</p>
</div>
<div class="paragraph">
<p>For the definition of join and meet for union types, we define how a type is added to a union type:</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-21"></a><strong>Req. IDE-21:</strong> <a href="#Req-IDE-21">Union of union type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The union of union types is defined similar to the union of sets.
The union is not simplified, but it contains no duplicates.</p>
</div>
<div class="paragraph">
<p>If a type A is contained in a union type, then the union type is a common supertype, and (since it is the union itself) also the <code><a href="appendix_a_acronyms.html#_acronyms">LCST</a></code> of both types.
This finding is the foundation of the definition of join of a (non-union) type with a union type:</p>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-22"></a><strong>Req. IDE-22:</strong> <a href="#Req-IDE-22">Join with Union Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The join <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>J</mi></math> of a union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> with a type <em>T</em> is the union of both types:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>J</mi><mo>=</mo><mi>U</mi><mo>∪</mo><mi>T</mi></mrow><mrow><mfenced close=")" open="("><mrow><mi>U</mi><mo>∨</mo><mi>T</mi></mrow></mfenced><mo>=</mo><mi>J</mi></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>Remarks:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Joining a union type with another type is not similar to joining the elements of the union type directly with another type.
That is</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>A</mi><mspace width="3.0mm"/><mstyle mathvariant="bold"><mi>j</mi><mi>o</mi><mi>i</mi><mi>n</mi></mstyle><mspace width="3.0mm"/><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>B</mi><mo>,</mo><mi>C</mi></mrow></mfenced><mo>≠</mo><mi>A</mi><mspace width="3.0mm"/><mstyle mathvariant="bold"><mi>j</mi><mi>o</mi><mi>i</mi><mi>n</mi></mstyle><mspace width="3.0mm"/><mi>B</mi><mspace width="3.0mm"/><mstyle mathvariant="bold"><mi>j</mi><mi>o</mi><mi>i</mi><mi>n</mi></mstyle><mspace width="3.0mm"/><mi>C</mi></math>
</div>
</div>
</li>
<li>
<p>The computed join is simplified according to the constraints defined above.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-23"></a><strong>Req. IDE-23:</strong> <a href="#Req-IDE-23">Meet with Union Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The meet of union types is defined as the meet of the elements.
That is</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>∧</mo><mi>S</mi><mo>∧</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>∧</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∧</mo><mi>S</mi></mrow><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mo>∧</mo><mi>S</mi></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>∧</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mn>1</mn></msub><mo>∧</mo><msub><mi>S</mi><mi>m</mi></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∧</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∧</mo><msub><mi>S</mi><mi>m</mi></msub></mrow><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mo>∧</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>m</mi></msub></mrow></mfenced></mrow></mfrac></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p>Remarks:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The meet of a union type with another type is not a union type itself.
This gets clear when looking at the definition of meet and union type.
While for a given <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>A</mi><mo>,</mo><mi>B</mi></mrow></mfenced></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>U</mi></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>U</mi></math>, the opposite <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></math> is usually not true (unless <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> can be simplified to <em>A</em>).
So, for <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>∧</mo><mi>U</mi></math>, usually <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> cannot be the meet.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-24"></a><strong>Req. IDE-24:</strong> <a href="#Req-IDE-24">Upper and Lower Bound of a Union Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The upper and lower bound of a union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math> is a union type <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>U</mi><mi>'</mi></msup></math> containing the upper and lower bound of the elements of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi></math>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow></mfenced><mi>:</mi><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced></mrow></mfenced></mtd></mtr><mtr><mtd><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><mrow><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow></mfenced><mi>:</mi><mo>=</mo><mi>u</mi><mi>n</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced></mrow></mfenced></mtd></mtr></mtable></math>
</div>
</div>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_warnings"><a class="anchor" href="#_warnings"></a><a class="link" href="#_warnings">4.10.1.3. Warnings</a></h5>
<div class="paragraph">
<p>In case the <code>any</code> type is used in a union type, all other types in the union type definition become obsolete.
However, defining other typers along with the <code>any</code> type might seem reasonable in case those other types are treated specifically and thus are mentioned explicitly in the definition.
Nevertheless the use of the <code>any</code> type produces a warning, since its use can indicate a misunderstanding of the union type concept and since documentation can also be done in a comment.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-25"></a><strong>Req. IDE-25:</strong> <a href="#Req-IDE-25">Any type in union types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>No union type shall conatin an type:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>∄</mo><mi>a</mi><mi>n</mi><mi>y</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi></math>
</div>
</div>
<div class="paragraph">
<p>Similar to the documentary purpose of using specific classes along with the <code>any</code> type is the following case.
When two types are used, one of them a subtype of the other, then this subtype is obsolete. Still it can be used for documentary purposes.
However, a warning will be produced to indicate unecessary code.
The warning is only produced when both of the types are either classes or interfaces, since e.g. structural types are supertypes of any classes or interfaces.</p>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-26"></a><strong>Req. IDE-26:</strong> <a href="#Req-IDE-26">Redundant subtypes in union types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Union types shall not
contain class or interface types which are a subtype of another class or interface type that also is contained in the union type.</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mo>∄</mo><mi>T</mi><mi>T</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mo>∃</mo><mi>T</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi></mtd></mtr><mtr><mtd><mrow><mo>(</mo><mrow><mi>T</mi><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi><mo>∧</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>O</mi><mi>r</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∧</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>O</mi><mi>r</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mrow><mi>T</mi><mi>T</mi></mrow></mfenced><mo>)</mo></mrow></mrow></mtd></mtr></mtable></math>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_intersection-type"><a class="anchor" href="#_intersection-type"></a><a class="link" href="#_intersection-type">4.10.2. Intersection Type</a></h4>
<div class="paragraph">
<p>Intersection type reflects the dynamic nature of JavaScript, similar to union type.
As in Java, intersection type is used to define the type boundaries of type variables in type parameter definitions.
They are inferred by the type inferencer for type checking (as a result of join or meet).
In contrast to Java, however, intersection type can be declared explicitly by means of intersection type expression.<sup class="footnote">[<a id="_footnoteref_19" class="footnote" href="appendix_c_bibliography.html#_footnote_19" title="View footnote.">19</a>]</sup></p>
</div>
<div class="sect4">
<h5 id="intersection-type-syntax"><a class="anchor" href="#intersection-type-syntax"></a><a class="link" href="#intersection-type-syntax">4.10.2.1. Syntax</a></h5>
<div class="paragraph">
<p>For convenience, we repeat the definition of intersection type expression and of type variables in which intersection types can be defined as in Java:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">InterSectionTypeExpression: 'intersection' '{' typeRefs+=TypeRefWithoutModifiers (',' typeRefs+=TypeRefWithoutModifiers)* '}';

TypeVariable:   name=IDENTIFIER ('extends' declaredUpperBounds+=ParameterizedTypeRefNominal ('&amp;' declaredUpperBounds+=ParameterizedTypeRefNominal)*)?</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="intersection-type-semantics"><a class="anchor" href="#intersection-type-semantics"></a><a class="link" href="#intersection-type-semantics">4.10.2.2. Semantics</a></h5>
<div class="paragraph">
<p>An intersection type may contain several interfaces but only one class.
It virtually declares a subclass of this one class and implements all interfaces declared in the intersection type.
If no class is declared in the intersection type, the intersection type virtually declares a subclass of an N4Object instead.
This virtual subclass also explains why only one single class may be contained in the intersection.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-27"></a><strong>Req. IDE-27:</strong> <a href="#Req-IDE-27">Intersection Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given intersection type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi></math>, the following conditions must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The intersection must contain at least one type:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>≠</mo><mi>∅</mi></math>
</div>
</div>
</li>
<li>
<p>Only one nominally typed class must be contained in the intersection type:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfenced close=")" open="("><mrow><mo>∃</mo><mi>C</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mi>μ</mi><mfenced close=")" open="("><mi>C</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Class</mtext></mstyle><mo>∧</mo><mi>C</mi><mo>.</mo><mi>i</mi><mi>s</mi><mi>S</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mi>u</mi><mi>r</mi><mi>a</mi><mi>l</mi></mrow></mfenced><mo>→</mo><mo>∄</mo><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>∖</mo><mfenced close="}" open="{"><mi>C</mi></mfenced><mi>:</mi><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>Class</mtext></mstyle><mo>∧</mo><mi>T</mi><mo>.</mo><mi>i</mi><mi>s</mi><mi>S</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mi>u</mi><mi>r</mi><mi>a</mi><mi>l</mi></math>
</div>
</div>
<div class="paragraph">
<p>A warning is produced when more than one nominal class is contained in the intersection type, since
only undefined (or null) can be assigned to a type reference of this type.</p>
</div>
</li>
<li>
<p>Non-optional elements:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>∀</mo><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>→</mo><mo>¬</mo><mi>T</mi><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></math>
</div>
</div>
</li>
<li>
<p>If the intersection contains multiple references to the same generic type, a warning is produced if only undefined (or null) can be assigned to a type reference of this type. There are some rare cases in which this does not happen. This is true if for all type arguments one of the following conditions hold:</p>
<div class="ulist">
<ul>
<li>
<p>a type argument corresponding to a type parameter without def-site variance is a wildcard with an upper bound (use "extends" or no bound) or a type argument not defining an upper bound corresponds to a covariant (out) type parameter, and this constraint (IDE-27) holds for an intersection created from the upper bounds of the type argument (or the lower bound of the type parameter).</p>
</li>
<li>
<p>a type argument is a wildcard with lower bounds (since Object would be a solution)</p>
</li>
</ul>
</div>
</li>
</ol>
</div>
</div>
</div>
<div class="paragraph">
<p>Definition of structural typing attributes see <a href="#Req-ID-78701">[Req-ID-78701]</a>.</p>
</div>
<div class="paragraph">
<p>The combination of intersection types and generics is a bit tricky. The following example demonstrates that:</p>
</div>
<div class="exampleblock">
<div class="title">Example 20. Intersection and generics</div>
<div class="content">
<div class="paragraph">
<p>Given the following types:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>class G&lt;T&gt; {
     private T: t
	set(t: T) { this.t = t;}
	get(): T { return this.t; }
}
class C { public y; }
class D { public x; }
interface I {}</pre>
</div>
</div>
<div class="paragraph">
<p>We use the generic with the getter and setter here only to demonstrate co- and contra variance effects.</p>
</div>
<div class="paragraph">
<p>Let</p>
</div>
<div class="listingblock">
<div class="content">
<pre>let g1: G&lt;C&gt; &amp; G&lt;D&gt;;</pre>
</div>
</div>
<div class="paragraph">
<p>be a variable. We can only assign undefined to g1, since any other value would not be confirm to the intersection.
If we for example would assign</p>
</div>
<div class="listingblock">
<div class="content">
<pre>let gc = new G&lt;C&gt;()
g1 = gc;</pre>
</div>
</div>
<div class="paragraph">
<p>we would run into contra-variance problems:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>gc.set(new C());</pre>
</div>
</div>
<div class="paragraph">
<p>This would implicitly also set a <code>C</code> in <code>g1</code>, which would not be compatible with <code>D</code>. This would lead to a problem in the following lines:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>let gd: G&lt;D&gt; = g1;
let d: D = gd.get();</pre>
</div>
</div>
<div class="paragraph">
<p>This is the typical contra variance problem.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>Similar problems arise even with structural types.</p>
</div>
<div class="paragraph">
<p>Note that in theory more warnings could be produced, in particular in combination with
structural types (and the fact that N4JS classes must explicitly implement even
structural interfaces). We omit these kind of warnings for two reasons:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>performance</p>
</li>
<li>
<p>anticipated slight changes in semantics (e.g. we may remove the requirement of explicitly implementing structural interfaces)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Since problems caused by not instanceable type references will be detected by programmers before runtime anyway, we do not need to be strict here. They are merely convenience features and they do not affect the correctness of the type system.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-175"></a><strong>Req. IDE-175:</strong> <a href="#Req-IDE-175">Intersection Type Subtyping Rules</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Let <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi></math> be an intersection type.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>An intersection type is a subtype of another type, if at least one of
its contained types is a subtype of that type: <sup class="footnote">[<a id="_footnoteref_20" class="footnote" href="appendix_c_bibliography.html#_footnote_20" title="View footnote.">20</a>]</sup></p>
</li>
</ul>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mo>∃</mo><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow><mrow><mi>I</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi></mrow></mfrac></math>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>A type is a subtype of an intersection type, if it is a subtype of all
types contained in the intersection type: <sup class="footnote">[<a id="_footnoteref_21" class="footnote" href="appendix_c_bibliography.html#_footnote_21" title="View footnote.">21</a>]</sup></p>
</li>
</ul>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mo>∀</mo><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mi>S</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi></mrow><mrow><mi>S</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>I</mi></mrow></mfrac></math>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>Non-optional elements:
<math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mo>→</mo><mo>¬</mo><mi>T</mi><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></math></p>
</li>
</ul>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-28"></a><strong>Req. IDE-28:</strong> <a href="#Req-IDE-28">Implicit simplification of intersection types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Let <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi></math> be an intersection type.
The following simplification rules are always automatically applied to intersection types.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The structural typing strategy is propagated to the types of the intersection:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>~</mi><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>~</mi><msub><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mn>1</mn></msub><mo>,</mo><mi>…</mi><mo>,</mo><mi>~</mi><msub><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle><mi>n</mi></msub></mrow></mfenced></mrow></mfrac></math>
</div>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>These subtyping rules are similar to Ceylon. <sup class="footnote">[<a id="_footnoteref_22" class="footnote" href="appendix_c_bibliography.html#_footnote_22" title="View footnote.">22</a>]</sup></p>
</div>
<div class="paragraph">
<p>During validation, intersection types containing union or other intersection types may be inferred.
In this case, the composed types are flattened.
The aforementioned constraints must hold.
We also implicitly use this representation in this specification.</p>
</div>
<div class="exampleblock">
<div class="title">Example 21. Subtyping with intersection type</div>
<div class="content">
<div class="paragraph">
<p>Let A, B, and C be defined as in the chapter beginning (<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi><mo>&lt;</mo><mi>:</mi><mi>B</mi><mo>&lt;</mo><mi>:</mi><mi>A</mi></math>)</p>
</div>
<div class="paragraph">
<p>The following subtyping relations with intersection types are to be
evaluated as follows: <sup class="footnote">[<a id="_footnoteref_23" class="footnote" href="appendix_c_bibliography.html#_footnote_23" title="View footnote.">23</a>]</sup></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">A &lt;: intersection{A}                            -&gt; true
A &lt;: intersection{A,A}                          -&gt; true
intersection{A,X} &lt;: A                          -&gt; true
intersection{X,A} &lt;: A                          -&gt; true
A &lt;: intersection{A,X}                          -&gt; false
intersection{A,X} &lt;: intersection{X,A}          -&gt; true
H12 &lt;: intersection{I1,I2}                      -&gt; true
intersection{I1,I2} &lt;: H12                      -&gt; false
H1 &lt;: intersection{I1,I2}                       -&gt; false
H23 &lt;: intersection{I1,I2}                      -&gt; false
B &lt;: intersection{A}                            -&gt; true
intersection{I1,I2} &lt;: I                        -&gt; true
H12 &lt;: intersection{I,I2}                       -&gt; true
A &lt;: intersection{A,Any}                        -&gt; true
intersection{A,Any} &lt;: A                        -&gt; true</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The join of intersection types is defined as the join of the elements.
That is:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>∨</mo><mi>S</mi><mo>∨</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>∨</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∨</mo><mi>S</mi></mrow><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mo>∨</mo><mi>S</mi></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>∨</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mn>1</mn></msub><mo>∨</mo><msub><mi>S</mi><mi>m</mi></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∨</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∨</mo><msub><mi>S</mi><mi>m</mi></msub></mrow><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mo>∨</mo><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>m</mi></msub></mrow></mfenced></mrow></mfrac></math></p>
</div>
<div class="openblock">
<div class="content">

</div>
</div>
<div class="paragraph">
<p>The meet of intersection types is defined over their elements.
That is:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>∧</mo><mi>S</mi><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∧</mo><mi>S</mi></mrow></mfenced></mrow><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mo>∧</mo><mi>S</mi></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>∧</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mn>1</mn></msub><mo>∧</mo><msub><mi>S</mi><mi>m</mi></msub><mo>,</mo><mspace width="1em"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mspace width="1em"/><msub><mi>T</mi><mi>n</mi></msub><mo>∧</mo><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub><mo>∧</mo><msub><mi>S</mi><mi>m</mi></msub></mrow></mfenced></mrow><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced><mo>∧</mo><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>S</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>S</mi><mi>m</mi></msub></mrow></mfenced></mrow></mfrac></math></p>
</div>
<div class="openblock">
<div class="content">

</div>
</div>
<div class="paragraph">
<p>The upper and lower bound of an intersection type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi></math> is a union type <math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>I</mi><mi>'</mi></msup></math> containing the upper and lower bound of the elements of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi></math>:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow></mfenced><mi>:</mi><mo>=</mo><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced></mrow></mfenced></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><mrow><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><msub><mi>T</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>T</mi><mi>n</mi></msub></mrow></mfenced></mrow></mfenced><mi>:</mi><mo>=</mo><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>e</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mfenced close="}" open="{"><mrow><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mfenced close=")" open="("><msub><mi>T</mi><mn>1</mn></msub></mfenced></mrow></mfenced></math></p>
</div>
<div class="openblock">
<div class="content">

</div>
</div>
</div>
<div class="sect4">
<h5 id="_warnings-2"><a class="anchor" href="#_warnings-2"></a><a class="link" href="#_warnings-2">4.10.2.3. Warnings</a></h5>
<div class="paragraph">
<p>Using <code>any</code> types in intersection types is obsolete since they do not change the resulting intersection type.
E.g. the intersection type of A, B and <code>any</code> is equivialent to the intersection type of A and B.
However, using the <code>any</code> type is no error because it can be seen as a neutral argument to the intersection.
Nevertheless the use of the <code>any</code> type produces a warning, since its use can indicate a misunderstanding of the intersection type concept and since it always can be omitted.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-32"></a><strong>Req. IDE-32:</strong> <a href="#Req-IDE-32">Any type in intersection types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>No intersection type shall contain an type:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∄</mo><mi>a</mi><mi>n</mi><mi>y</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi></math></p>
</div>
</div>
</div>
<div class="paragraph">
<p>The use of the <code>any</code> type in an intersection type is similar to the following case.
When two types are used, one of them a supertype of the other, then this supertype is obsolete.
Hence, a warning will be produced to indicate unecessary code.
The warning is only produced when both of the types are either classes or interfaces, since e.g. structural types are supertypes of any classes or interfaces.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-33"></a><strong>Req. IDE-33:</strong> <a href="#Req-IDE-33">Redundant supertypes in intersection types</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Intersection types shall not contain class or interface types which are a supertype of another class or interface type that also is contained in the intersection type.</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>∄</mo><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mo>∃</mo><mi>T</mi><mi>T</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>s</mi><mi>:</mi><mtext>
</mtext><mrow><mo>(</mo><mrow><mi>T</mi><mi>T</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi><mo>∧</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>O</mi><mi>r</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>∧</mo><mi>i</mi><mi>s</mi><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>O</mi><mi>r</mi><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mfenced close=")" open="("><mrow><mi>T</mi><mi>T</mi></mrow></mfenced><mo>)</mo></mrow></mrow></math>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_composed-types-in-wildcards"><a class="anchor" href="#_composed-types-in-wildcards"></a><a class="link" href="#_composed-types-in-wildcards">4.10.3. Composed Types in Wildcards</a></h4>
<div class="paragraph">
<p>Composed types may appear as the bound of a wildcard.
The following constraints apply: <sup class="footnote">[<a id="_footnoteref_24" class="footnote" href="appendix_c_bibliography.html#_footnote_24" title="View footnote.">24</a>]</sup></p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-34"></a><strong>Req. IDE-34:</strong> <a href="#Req-IDE-34">Composed Types as Bound of a Wildcard</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>A composed type may appear as the upper or lower bound of a wildcard.
In the covariant case, the following subtype relations apply:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-ebnf" data-lang="ebnf">union{ G&lt;? extends A&gt;, G&lt;? extends B&gt; }  \subtype  G&lt;? extends union{A,B}&gt;
G&lt;? extends intersection{A,B}&gt;  \subtype  intersection{ G&lt;? extends A&gt;, G&lt;? extends B&gt; }</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the contra variant case, the following subtype relations apply:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-ebnf" data-lang="ebnf">union{ G&lt;? super A&gt;, G&lt;? super B&gt; }  \subtype  G&lt;? super intersection{A,B}&gt;
G&lt;? super union{A,B}&gt;  \subtype  intersection{ G&lt;? super A&gt;, G&lt;? super B&gt; }</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_property-access-for-composed-types"><a class="anchor" href="#_property-access-for-composed-types"></a><a class="link" href="#_property-access-for-composed-types">4.10.4. Property Access for Composed Types</a></h4>
<div class="paragraph">
<p>It is possible to directly access properties of union and intersection types.
The following sections define which properties are accessible.</p>
</div>
<div class="sect4">
<h5 id="_properties-of-union-type"><a class="anchor" href="#_properties-of-union-type"></a><a class="link" href="#_properties-of-union-type">4.10.4.1. Properties of Union Type</a></h5>
<div class="paragraph">
<p>As an (oversimplified) rule of thumb, the properties of a union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>=</mo><msub><mi>T</mi><mn>1</mn></msub><mo>|</mo><msub><mi>T</mi><mn>2</mn></msub></math> are simply the intersection of the properties <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>i</mi><mi>e</mi><mi>s</mi><mo>=</mo><msub><mi>T</mi><mn>1</mn></msub><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>i</mi><mi>e</mi><mi>s</mi><mo>∩</mo><msub><mi>T</mi><mn>2</mn></msub><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>i</mi><mi>e</mi><mi>s</mi></math>.
In other words, a property 'p' in the union type is the least common denominator of all 'p' in T_{1} and T_{2}.
It is not quite that simple, however, as the question of "equality" with regards to properties has to be answered.</p>
</div>
<hr>
<div class="paragraph">
<p>For a given union type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>U</mi><mo>=</mo><msub><mi>T</mi><mn>1</mn></msub><mo>|</mo><msub><mi>T</mi><mn>2</mn></msub></math>, the following constraints for its members must hold:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi> </mi><mi>a</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>a</mi><mi>t</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>b</mi><mi>u</mi><mi>t</mi><mi>e</mi><mi>s</mi><mi>:</mi></math></p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd/><mtd><mo>∀</mo><mi> </mi><mi>k</mi><mo>∈</mo><mfenced close="}" open="{"><mn>1</mn><mn>2</mn></mfenced><mi>:</mi><mo>∃</mo><mi> </mi><msub><mi>a</mi><mi>k</mi></msub><mo>∈</mo><msub><mi>T</mi><mi>k</mi></msub><mo>.</mo><mi>a</mi><mi>t</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>b</mi><mi>u</mi><mi>t</mi><mi>e</mi><mi>s</mi><mi>:</mi><msub><mi>a</mi><mi>k</mi></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>&gt;</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>v</mi><mi>a</mi><mi>t</mi><mi>e</mi></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>a</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mi>m</mi><mi>i</mi><mi>n</mi><mfenced close=")" open="("><mrow><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mrow><mrow><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mrow></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>a</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>a</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi> </mi><mi>m</mi><mo>∈</mo><mi>U</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi><mi>:</mi></math></p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∃</mo><mi> </mi><msub><mi>m</mi><mn>1</mn></msub><mo>∈</mo><msub><mi>T</mi><mn>1</mn></msub><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi><mo>,</mo><msub><mi>m</mi><mn>2</mn></msub><mo>∈</mo><msub><mi>T</mi><mn>2</mn></msub><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi><mo>,</mo></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><mstyle mathvariant="bold"><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mstyle><mi>p</mi><mo>=</mo><mi>m</mi><mo>.</mo><mi>f</mi><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi><mo>∧</mo><msup><mi>p</mi><mi>'</mi></msup><mo>=</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>f</mi><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi><mo>∧</mo><mi>p</mi><mi>"</mi><mo>=</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>f</mi><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi><mo>,</mo><mstyle mathvariant="bold"><mi>W</mi><mi>L</mi><mi>O</mi><mi>G</mi></mstyle><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>≤</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mi>:</mi></math><br></p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd/><mtd><mspace width="1.2em"/><mo>∀</mo><mi>k</mi><mo>∈</mo><mfenced close="}" open="{"><mn>1</mn><mn>2</mn></mfenced><mi>:</mi><msub><mi>m</mi><mi>k</mi></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>&gt;</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>v</mi><mi>a</mi><mi>t</mi><mi>e</mi></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>m</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mi>m</mi><mi>i</mi><mi>n</mi><mfenced close=")" open="("><mrow><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mrow><mrow><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mrow></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>m</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>m</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>|</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mo>∀</mo><mi> </mi><mi>i</mi><mo>&lt;</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mi>:</mi><msub><mi>p</mi><mi>i</mi></msub><mi> </mi><mstyle mathvariant="bold"><mi>e</mi><mi>x</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi>s</mi></mstyle><mspace width="1.0mm"/><mstyle mathvariant="bold"><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mstyle></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><mi>i</mi><mo>≥</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∨</mo><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd></mtr><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>+</mo><mstyle mathvariant="bold"><mi>"</mi><mi>_</mi><mi>"</mi></mstyle><mo>+</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>&amp;</mi><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mi>i</mi><mo>&lt;</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo></mtd></mtr><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mrow><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>-</mo><mn>1</mn></mrow></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>&amp;</mi><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mi>i</mi><mo>≥</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∧</mo><msub><msup><mi>p</mi><mi>'</mi></msup><mrow><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>-</mo><mn>1</mn></mrow></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi></mtd></mtr><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><mfenced close=")" open="("><mrow><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>∧</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></mrow></mfenced></mtd><mtd><mi>i</mi><mo>&lt;</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo></mtd></mtr><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>∧</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi></mtd><mtd><mi>i</mi><mo>&lt;</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∧</mo><mi>i</mi><mo>=</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mo>-</mo><mn>1</mn></mtd></mtr><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi></mtd><mtd><mi>i</mi><mo>≥</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∧</mo><mi>i</mi><mo>=</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mo>-</mo><mn>1</mn></mtd></mtr><mtr><mtd><mi>f</mi><mi>a</mi><mi>l</mi><mi>s</mi><mi>e</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∧</mo><mrow><mo>(</mo><mi>l</mi><mo>=</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>=</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mo>∧</mo><mo>¬</mo><mfenced close=")" open="("><mrow><msub><msup><mi>p</mi><mi>'</mi></msup><mi>l</mi></msub><mo>-</mo><mn>1</mn><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>∧</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mrow><mi>l</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></mrow></mfenced><mo>∧</mo><mo>∃</mo><mi>v</mi><mo>∈</mo><mfenced close="}" open="{"><mrow><mi>p</mi><msub><mi>'</mi><mi>l</mi></msub><mo>-</mo><mn>1</mn></mrow><mrow><mi>p</mi><msub><mi>"</mi><mi>l</mi></msub><mo>-</mo><mn>1</mn></mrow></mfenced><mi>v</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>:</mi><msub><mi>p</mi><mi>l</mi></msub><mi> </mi><mstyle mathvariant="bold"><mi>e</mi><mi>x</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi>s</mi></mstyle><mspace width="1.0mm"/><mstyle mathvariant="bold"><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mstyle></mrow></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>l</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mi>v</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><mi>v</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>=</mo><mi>t</mi><mi>r</mi><mi>u</mi><mi>e</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>=</mo><mi>t</mi><mi>r</mi><mi>u</mi><mi>e</mi></math></p>
</div>
<hr>
<div class="paragraph">
<p>The following table shows how non-method members of union types are merged.
The resulting member type depends on whether the member is being accessed during a read (R) or write (W) operation.
The type of a field, of a getter or of the parameter of a setter is indicated in brackets.</p>
</div>
<table class="tableblock frame-all grid-all spread">
<caption class="title">Table 4. Merged Members of Unions</caption>
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-center valign-top">Members</th>
<th class="tableblock halign-center valign-top" colspan="2">S=T</th>
<th class="tableblock halign-center valign-top" colspan="2">S≠T</th>
</tr>
</thead>
<tbody>
<tr>
<th class="tableblock halign-center valign-top"></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">R</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">W</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">R</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">W</p></th>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">field:S  | field:T</p></th>
<td class="tableblock halign-center valign-top" colspan="2"><p class="tableblock">field:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S|T</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S&amp;T</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">getter:S | getter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S|T</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">setter:S | setter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S&amp;T</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">field:S  | getter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S|T</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">field:S  | setter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S&amp;T</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">getter:S | setter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
</tr>
</tbody>
</table>
<div class="sect5">
<h6 id="_remarks-on-union-type-s-members"><a class="anchor" href="#_remarks-on-union-type-s-members"></a><a class="link" href="#_remarks-on-union-type-s-members">4.10.4.1.1. Remarks on union type’s members:</a></h6>
<div class="ulist">
<ul>
<li>
<p>Fields of the same type are merged to a composed field with the same type.
Fields of different types are merged to a getter and setter.</p>
</li>
<li>
<p>The return type of a composed getter is the <em>union</em> type of the return types of the merged getters.</p>
</li>
<li>
<p>The type of a composed setter is the <em>intersection</em> type of the types of the merged setters.</p>
</li>
<li>
<p>Fields can be combined with getters and/or setters:</p>
<div class="ulist">
<ul>
<li>
<p>fields combined with getters allow read-access.</p>
</li>
<li>
<p>non-const fields combined with setters allow write-access.</p>
</li>
<li>
<p>non-const fields combined with getters <em>and</em> setters, i.e. each type has either a non-const field or both a getter and a setter of the given name, allow both read- and write-access.</p>
<div class="paragraph">
<p>Again, types need not be identical; for read-access the <em>union</em> of the fields’ types and the getters’ return types is formed, for write-access the <em>intersection</em> of the fields’ types and the setters’ types is formed.
In the third case above, types are combined independently for read- and write-access if the getters and setters have different types.</p>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>The name of a method’s parameter is only used for error or warning messages and cannot be referenced otherwise.</p>
</li>
<li>
<p>The return type of a composed method is the <em>union</em> type of the return types of the merged methods.</p>
</li>
<li>
<p>A composed method parameter’s type is the <em>intersection</em> type of the merged parameters types.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_properties-of-intersection-type"><a class="anchor" href="#_properties-of-intersection-type"></a><a class="link" href="#_properties-of-intersection-type">4.10.4.2. Properties of Intersection Type</a></h5>
<div class="paragraph">
<p>As an (oversimplified) rule of thumb, the properties of an intersection type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi><mo>=</mo><msub><mi>T</mi><mn>1</mn></msub><mi>&amp;</mi><msub><mi>T</mi><mn>2</mn></msub></math> are the union of properties <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>i</mi><mi>e</mi><mi>s</mi><mo>=</mo><msub><mi>T</mi><mn>1</mn></msub><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>i</mi><mi>e</mi><mi>s</mi><mo>∪</mo><msub><mi>T</mi><mn>2</mn></msub><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>t</mi><mi>i</mi><mi>e</mi><mi>s</mi></math>.
In other words, a property 'p' in the union type is the greates common denominator of all 'p' in T_{1} and T_{2}.
It is not quite that simple, however, as the question of "equality” with regards to properties has to be answered.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-36"></a><strong>Req. IDE-36:</strong> <a href="#Req-IDE-36">Members of an Intersection Type</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given intersection type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>I</mi><mo>=</mo><msub><mi>T</mi><mn>1</mn></msub><mi>&amp;</mi><msub><mi>T</mi><mn>2</mn></msub></math>, the following constraints for its members must hold:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>a</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>a</mi><mi>t</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>b</mi><mi>u</mi><mi>t</mi><mi>e</mi><mi>s</mi><mi>:</mi></math></p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd/><mtd><mrow><mo>(</mo><mrow><mo>∃</mo><msub><mi>a</mi><mn>1</mn></msub><mo>∈</mo><msub><mi>T</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>t</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>b</mi><mi>u</mi><mi>t</mi><mi>e</mi><mi>s</mi><mo>,</mo><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>&gt;</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>v</mi><mi>a</mi><mi>t</mi><mi>e</mi><mo>)</mo></mrow><mo>∨</mo><mrow><mo>(</mo><mrow><mo>∃</mo><msub><mi>a</mi><mn>2</mn></msub><mo>∈</mo><msub><mi>T</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>t</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>b</mi><mi>u</mi><mi>t</mi><mi>e</mi><mi>s</mi><mo>,</mo><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>&gt;</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>v</mi><mi>a</mi><mi>t</mi><mi>e</mi><mo>)</mo></mrow></mrow></mrow></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>a</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mfenced close=")" open="("><mrow><msub><mi>a</mi><mn>2</mn></msub><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∨</mo><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mrow></mfenced></mtd></mtr><mtr><mtd><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>a</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mtd><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mfenced close=")" open="("><mrow><msub><mi>a</mi><mn>2</mn></msub><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∨</mo><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>≤</mo><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mrow></mfenced></mtd></mtr><mtr><mtd><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>a</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>&amp;</mi><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><msub><mi>a</mi><mn>2</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mtd></mtr><mtr><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><msub><mi>a</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mtd></mtr><mtr><mtd><msub><mi>a</mi><mn>2</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle><mfenced close=")" open="("><mrow><msub><mi>a</mi><mn>2</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mrow></mfenced></mtd></mtr></mtable></mfenced></mtd></mtr></mtable></math>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>m</mi><mo>∈</mo><mi>I</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi></math>:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>(</mo><mrow><mo>∃</mo><msub><mi>m</mi><mn>1</mn></msub><mo>∈</mo><msub><mi>T</mi><mn>1</mn></msub><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi><mo>,</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>&gt;</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>v</mi><mi>a</mi><mi>t</mi><mi>e</mi><mo>)</mo></mrow><mo>∨</mo><mrow><mo>(</mo><mrow><mo>∃</mo><msub><mi>m</mi><mn>2</mn></msub><mo>∈</mo><msub><mi>T</mi><mn>1</mn></msub><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><mi>s</mi><mo>,</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>&gt;</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>v</mi><mi>a</mi><mi>t</mi><mi>e</mi><mo>)</mo></mrow><mi>:</mi></mrow></mrow></math></p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd/><mtd><mspace width="2.0em"/><mstyle mathvariant="bold"><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mstyle><mi>p</mi><mo>=</mo><mi>m</mi><mo>.</mo><mi>f</mi><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi></mtd></mtr><mtr><mtd/><mtd><mspace width="3.0em"/><mo>∧</mo><mstyle mathvariant="bold"><mi>i</mi><mi>f</mi></mstyle><mi> </mi><msub><mi>m</mi><mn>1</mn></msub><mi> </mi><mstyle mathvariant="bold"><mi>e</mi><mi>x</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi>s</mi></mstyle><mi> </mi><msup><mi>p</mi><mi>'</mi></msup><mo>=</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>f</mi><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi><mi> </mi><mstyle mathvariant="bold"><mfenced close=")" open="("><mrow><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi><msup><mi>p</mi><mi>'</mi></msup><mo>=</mo><mi>∅</mi></mrow></mfenced></mstyle><mo>,</mo></mtd></mtr><mtr><mtd/><mtd><mspace width="3.0em"/><mo>∧</mo><mstyle mathvariant="bold"><mi>i</mi><mi>f</mi></mstyle><mi> </mi><msub><mi>m</mi><mn>2</mn></msub><mi> </mi><mstyle mathvariant="bold"><mi>e</mi><mi>x</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi>s</mi></mstyle><mi> </mi><mi>p</mi><mi>"</mi><mo>=</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>f</mi><mi>p</mi><mi>a</mi><mi>r</mi><mi>s</mi><mi> </mi><mstyle mathvariant="bold"><mfenced close=")" open="("><mrow><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi><mi>p</mi><mi>"</mi><mo>=</mo><mi>∅</mi></mrow></mfenced></mstyle><mo>,</mo><mstyle mathvariant="bold"><mstyle mathvariant="bold"><mi>W</mi><mi>L</mi><mi>O</mi><mi>G</mi></mstyle></mstyle><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>≤</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mi>:</mi></mtd></mtr><mtr><mtd/><mtd><mspace width="1.0em"/><mi>m</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mfenced close=")" open="("><mrow><msub><mi>m</mi><mn>2</mn></msub><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∨</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mrow></mfenced></mtd></mtr><mtr><mtd><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>m</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mtd><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><mfenced close=")" open="("><mrow><msub><mi>m</mi><mn>2</mn></msub><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∨</mo><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>≤</mo><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mrow></mfenced></mtd></mtr><mtr><mtd><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mi>m</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>&amp;</mi><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi><mo>∧</mo><msub><mi>m</mi><mn>2</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mtd></mtr><mtr><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><msub><mi>m</mi><mn>1</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mtd></mtr><mtr><mtd><msub><mi>m</mi><mn>2</mn></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle><mfenced close=")" open="("><mrow><msub><mi>m</mi><mn>2</mn></msub><mo>≠</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mrow></mfenced></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mo>∧</mo><mo>∀</mo><mi> </mi><mi>i</mi><mo>&lt;</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mi>:</mi><msub><mi>p</mi><mi>i</mi></msub><mi> </mi><mstyle mathvariant="bold"><mi>e</mi><mi>x</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi>s</mi><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mstyle></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><mi>i</mi><mo>≥</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∨</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd></mtr><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>+</mo><mstyle mathvariant="bold"><mi>"</mi><mi>_</mi><mi>"</mi></mstyle><mo>+</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>|</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mi>i</mi><mo>&lt;</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo></mtd></mtr><mtr><mtd><msub><msup><mi>p</mi><mi>'</mi></msup><mrow><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>-</mo><mn>1</mn></mrow></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>|</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mi>i</mi><mo>≥</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∧</mo><msub><msup><mi>p</mi><mi>'</mi></msup><mrow><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>-</mo><mn>1</mn></mrow></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi></mtd></mtr><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>=</mo><mfenced close=")" open="("><mrow><mo>∃</mo><mi>k</mi><mo>≤</mo><mi>m</mi><mi>i</mi><mi>n</mi><mfenced close=")" open="("><mrow><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>-</mo><mn>1</mn></mrow><mi>i</mi></mfenced><mi>:</mi><mi>p</mi><msub><mi>'</mi><mi>k</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></mrow></mfenced><mo>∨</mo><mfenced close=")" open="("><mrow><mo>∃</mo><mi>k</mi><mo>≤</mo><mi>i</mi><mi>:</mi><mi>p</mi><msub><mi>"</mi><mi>k</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></mrow></mfenced></mtd></mtr><mtr><mtd/><mtd><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>=</mo><mfenced close="" open="{"><mtable><mtr><mtd><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>∨</mo><mfenced close=")" open="("><mrow><msub><msup><mi>p</mi><mi>'</mi></msup><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>∨</mo><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi></mrow></mfenced></mtd><mtd><mi>i</mi><mo>&lt;</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∧</mo><mi>i</mi><mo>=</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mo>-</mo><mn>1</mn></mtd></mtr><mtr><mtd><msub><mrow><mi>p</mi><mi>"</mi></mrow><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi></mtd><mtd><mi>i</mi><mo>≥</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>∧</mo><mi>i</mi><mo>=</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mo>-</mo><mn>1</mn></mtd></mtr><mtr><mtd><mi>f</mi><mi>a</mi><mi>l</mi><mi>s</mi><mi>e</mi></mtd><mtd><mstyle mathvariant="bold"><mi>e</mi><mi>l</mi><mi>s</mi><mi>e</mi></mstyle></mtd></mtr></mtable></mfenced></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∧</mo><mrow><mo>(</mo><mi>l</mi><mo>=</mo><mo>|</mo><msup><mi>p</mi><mi>'</mi></msup><mo>|</mo><mo>=</mo><mo>|</mo><mi>p</mi><mi>"</mi><mo>|</mo><mo>∧</mo><mi>l</mi><mo>&gt;</mo><mn>0</mn><mo>∧</mo><mo>¬</mo><mfenced close=")" open="("><mrow><msub><mi>p</mi><mrow><mi>l</mi><mo>-</mo><mn>1</mn></mrow></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi></mrow></mfenced><mo>∧</mo><mo>∃</mo><mi>v</mi><mo>∈</mo><mfenced close="}" open="{"><mrow><mi>p</mi><msub><mi>'</mi><mrow><mi>l</mi><mo>-</mo><mn>1</mn></mrow></msub></mrow><mrow><mi>p</mi><msub><mi>"</mi><mrow><mi>l</mi><mo>-</mo><mn>1</mn></mrow></msub></mrow></mfenced><mi>v</mi><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mi>:</mi><msub><mi>p</mi><mi>l</mi></msub><mi> </mi><mstyle mathvariant="bold"><mi>e</mi><mi>x</mi><mi>i</mi><mi>s</mi><mi>t</mi><mi>s</mi></mstyle><mspace width="1.0mm"/><mstyle mathvariant="bold"><mi>w</mi><mi>i</mi><mi>t</mi><mi>h</mi></mstyle></mrow></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>l</mi></msub><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mi>v</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mo>=</mo><mi>v</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>o</mi><mi>p</mi><mi>t</mi><mo>=</mo><mi>t</mi><mi>r</mi><mi>u</mi><mi>e</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mspace width="2.0em"/><msub><mi>p</mi><mi>i</mi></msub><mo>.</mo><mi>v</mi><mi>a</mi><mi>r</mi><mo>=</mo><mi>t</mi><mi>r</mi><mi>u</mi><mi>e</mi></math></p>
</div>
</div>
</div>
<div class="paragraph">
<p>The following table shows how non-method members of intersection types are merged.
The resulting member type depends on whether the member is being accessed during a read (R) or write (W) operation.
The type of a field, of a getter or of the parameter of a setter is indicated in brackets.</p>
</div>
<table class="tableblock frame-all grid-all spread">
<caption class="title">Table 5. Merged Members of Intersections</caption>
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-center valign-top">Members</th>
<th class="tableblock halign-center valign-top" colspan="2">S=T</th>
<th class="tableblock halign-center valign-top" colspan="2">S≠T</th>
</tr>
</thead>
<tbody>
<tr>
<th class="tableblock halign-center valign-top"></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">R</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">W</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">R</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">W</p></th>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">field:S   &amp; field:T</p></th>
<td class="tableblock halign-center valign-top" colspan="2"><p class="tableblock">field:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S&amp;T</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S|T</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">getter:S  &amp; getter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S&amp;T</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">setter:S  &amp; setter:T</p></th>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S|T</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">field:S   &amp; getter:T</p></th>
<td class="tableblock halign-center valign-top" colspan="2"><p class="tableblock">field:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S&amp;T</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">field:S   &amp; setter:T</p></th>
<td class="tableblock halign-center valign-top" colspan="2"><p class="tableblock">field:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:S|T</p></td>
</tr>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">getter:S  &amp; setter:T</p></th>
<td class="tableblock halign-center valign-top" colspan="2"><p class="tableblock">field:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">getter:S</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">setter:T</p></td>
</tr>
</tbody>
</table>
<div class="sect5">
<h6 id="_remarks-on-intersection-type-s-methods"><a class="anchor" href="#_remarks-on-intersection-type-s-methods"></a><a class="link" href="#_remarks-on-intersection-type-s-methods">4.10.4.2.1. Remarks on intersection type’s methods:</a></h6>
<div class="ulist">
<ul>
<li>
<p>The name of a method’s parameter is only used for error or warning messages and cannot be referenced otherwise.</p>
</li>
<li>
<p>The return type of a method is the <em>intersection</em> type of the return types of the merged methods.</p>
</li>
<li>
<p>A method parameter’s type is the <em>union</em> type of the merged parameters types.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_constructor-and-classifier-type"><a class="anchor" href="#_constructor-and-classifier-type"></a><a class="link" href="#_constructor-and-classifier-type">4.11. Constructor and Classifier Type</a></h3>
<div class="paragraph">
<p>A class definition as described in <a href="classifiers.html#_classes">Classes</a> declares types.
Often, it is necessary to access these types directly, for example to access staticmembers or for dynamic construction of instances.
These two use cases are actually slightly different and N4JS provides two different types, one for each use case: constructor and classifier type.<sup class="footnote">[<a id="_footnoteref_25" class="footnote" href="appendix_c_bibliography.html#_footnote_25" title="View footnote.">25</a>]</sup>
The constructor is basically the classifier type with the additional possibility to call it via <code>new</code> in order to create new instances of the declared type.</p>
</div>
<div class="paragraph">
<p>Both <code>meta</code> types are different from Java’s type <code>Class&lt;T&gt;</code>, as the latter has a defined set of members, while the N4JS metatypes will have members according to a class definition.
The concept of constructors as metatypes is similar to ECMAScript 2015 [<a href="appendix_c_bibliography.html#ECMA15a">ECMA15a(p.14.5)</a>].</p>
</div>
<div class="sect3">
<h4 id="_syntax-3"><a class="anchor" href="#_syntax-3"></a><a class="link" href="#_syntax-3">4.11.1. Syntax</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">ConstructorTypeRef returns ConstructorTypeRef: 'constructor' '{' typeArg = [TypeArgument] '}';

ClassifierTypeRef returns ClassifierTypeRef: 'type' '{' typeArg = [TypeRef] '}';</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_semantics-2"><a class="anchor" href="#_semantics-2"></a><a class="link" href="#_semantics-2">4.11.2. Semantics</a></h4>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Static members of a type <em>T</em> are actually members of the classifier type <code>type{T}</code>.</p>
</li>
<li>
<p>The keyword <code>this</code> in a static method of a type <em>T</em> actually binds to the classifier type <code>type{T}</code>.</p>
</li>
<li>
<p>The constructor type <code>constructor</code><em>{T}</em> is a subtype of the classifier type <code>type{T}</code>:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>∀</mo><mi>T</mi><mi>:</mi><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mi>o</mi><mi>r</mi><mfenced close="}" open="{"><mi>T</mi></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mfenced close="}" open="{"><mi>T</mi></mfenced></math>
</div>
</div>
</li>
<li>
<p>If a class <em>B</em> is a subtype (subclass) of a class <em>A</em>, then the classifier type <code>type{B}</code> also is a subtype of <code>type{A}</code>:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></mrow><mrow><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mfenced close="}" open="{"><mi>B</mi></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mfenced close="}" open="{"><mi>A</mi></mfenced></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>If a class <em>B</em> is a subtype (subclass) of a class <em>A</em>, and if the constructor function of <em>B</em> is a subtype of the constructor function of <em>A</em>, then the
classifier type <code>constructor{B}</code> also is a subtype of <code>constructor{A}</code> :</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi><mspace width="3.0mm"/><mi>B</mi><mo>.</mo><mi>c</mi><mi>t</mi><mi>o</mi><mi>r</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi><mo>.</mo><mi>c</mi><mi>t</mi><mi>o</mi><mi>r</mi></mrow><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mi>o</mi><mi>r</mi><mfenced close="}" open="{"><mi>B</mi></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi><mi>r</mi><mi>u</mi><mi>c</mi><mi>t</mi><mi>o</mi><mi>r</mi><mfenced close="}" open="{"><mi>A</mi></mfenced></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>The subtype relation of the constructor function is defined in <a href="functions.html#_function-type">Function Type</a>.
In the case of the default <code>N4Object</code> constructor, the type of the object literal argument depends on required attributes.</p>
</div>
<div class="paragraph">
<p>This subtype relation for the constructor type is enforced if the constructor of the super class is marked as <code>final</code>, see <a href="#_constructor-and-classifier-type">Constructor and Classifier Type</a> for details.</p>
</div>
</li>
<li>
<p>The type of a classifier declaration or classifier expression is the constructor of that class:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>μ</mi><mfenced close=")" open="("><mi>C</mi></mfenced><mo>∈</mo><mfenced close="}" open="{"><mrow><mi>c</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>f</mi><mi>i</mi><mi>e</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>f</mi><mi>i</mi><mi>n</mi><mi>i</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi></mrow></mfenced></mrow><mrow><mi>Γ</mi><mo>⊢</mo><mi>C</mi><mi>:</mi><mstyle mathvariant="monospace"><mtext>constructor[C]</mtext></mstyle></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>A class cannot be called as a function in ECMAScript.
Thus, the constructor and type type are only subtype of <code>Object</code>:</p>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>T</mi><mi>:</mi></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>constructor</mtext></mstyle><mfenced close="}" open="{"><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>Object</mtext></mstyle></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>type</mtext></mstyle><mfenced close="}" open="{"><mstyle mathvariant="monospace"><mtext>T</mtext></mstyle></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>Object</mtext></mstyle></math></p>
</div>
</li>
<li>
<p>If the type argument of the constructor is not a declared type (i.e., a wildcard or a type variable with bounds), the constructor cannot be used in a new expression.
Thus, the constructor function signature becomes irrelevant for subtype checking.
In that case, the following rules apply:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow><mi>S</mi><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>T</mi><mo>.</mo><mi>u</mi><mi>p</mi><mi>p</mi><mi>e</mi><mi>r</mi><mspace width="3.0mm"/><mi>T</mi><mo>.</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>S</mi><mo>.</mo><mi>l</mi><mi>o</mi><mi>w</mi><mi>e</mi><mi>r</mi><mspace width="3.0mm"/><mi>μ</mi><mfenced close=")" open="("><mi>T</mi></mfenced><mo>≠</mo><mstyle mathvariant="monospace"><mtext>DeclaredTypeWithAccessModifier</mtext></mstyle></mrow><mrow><mstyle mathvariant="monospace"><mtext>constructor</mtext><mtext>S</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>constructor</mtext><mtext>T</mtext></mstyle></mrow></mfrac></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p>Note that this is only true for the right hand side of the subtyping rule.
A constructor type with a wildcard is never a subtype of a constructor type without a wildcard.</p>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>The figure <a href="#cdConstructorClassifierType">Classifier and Constructor Type Subtype Relations</a> shows the subtype relations defined by the preceding rules.</p>
</div>
<div id="cdConstructorClassifierType" class="imageblock" style="text-align: center">
<div class="content">
<img src="chapters/04_types/fig/cdConstructorClassifierType.svg" alt="cdConstructorClassifierType">
</div>
<div class="title">Figure 4. Classifier and Constructor Type Subtype Relations</div>
</div>
<div class="paragraph">
<p>Consequences:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Overriding of static methods is possible and by using the constructor or classifier type, polymorphism for static methods is possible as well.</p>
<div id="_polymorphism-and-static-methods" class="exampleblock">
<div class="title">Example 22. Static Polymorphism</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {
    static foo(): string { return "A"; }
    static bar(): string { return this.foo(); }
}
class B extends A {
    @Override
    static foo(): string { return "B"; }
}

A.bar(); // will return "A"
B.bar(); // will return "B", as foo() is called polymorphical</code></pre>
</div>
</div>
</div>
</div>
</li>
<li>
<p>It is even possible to refer to the constructor of an abstract class.
The abstract class itself cannot provide this constructor (it only provides a type..), that is to say only concrete subclasses can provide constructors compatible to the constructor.</p>
<div class="exampleblock">
<div class="title">Example 23. Constructor of Abstract Class</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">abstract class A {}
class B extends A {}
function f(ctor: constructor{A}): A { return new ctor(); }

f(A); // not working: type{A} is not a subtype of constructor{A}.
f(B); // ok</code></pre>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>Allowing wildcards on constructor type references has pragmatic reasons.
The usage of constructor references usually indicates very dynamic scenarios.
In some of these scenarios, e.g., in case of dynamic creation of objects in the context of generic testing or injectors, arbitrary constructors may be used.
Of course, it won’t be possible to check the correct new expression call in these cases – and using new expressions is prevented by N4JS if the constructor reference contains a wildcard.
But other constraints, implemented by the client logic, may guarantee correct instantiation via more dynamic constructors, for example via the ECMAScript 2015 reflection API.
In order to simplify these scenarios and preventing the use of <code>any</code>, wildcards are supported in constructors. Since a constructor with a wildcard cannot be used
in a new expression anyway, using a classifier type is usually better than using a constructor type with wildcard.</p>
</div>
<div class="paragraph">
<p>Using wildcards on classifier types would have the same meaning as using the upper bound directly.
That is, a type reference <code>type{? extends C}</code> can simply be replaced with <code>type{c}</code>, and <code>type{?}</code> with <code>type{any}</code>.</p>
</div>
<div class="paragraph">
<p>To conclude this chapter, let us compare the different types introduced above depending on whether they are used with wildcards or not:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>having a value of type <code>constructor{C}</code>, we know we have</p>
<div class="ulist">
<ul>
<li>
<p>a constructor function of <code>{C}</code> or a subclass of <code>{C}</code>,</p>
</li>
<li>
<p>that can be used for instantiation (i.e. the represented class is not abstract),</p>
</li>
<li>
<p>that has a signature compatible to the owned or inherited constructor of <code>{C}</code>.</p>
<div class="paragraph">
<p>This means we have the constructor function of class <code>{C}</code> (but only if is non-abstract) or the constructor function of any non-abstract
subclass of <code>{C}</code> with an override compatible signature to that of <code>{C}</code>'s constructor function.</p>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>having a value of type <code>constructor{? extends C}</code>, we know we have</p>
<div class="ulist">
<ul>
<li>
<p>a constructor function of <code>{C}</code> or a subclass of <code>{C}</code>,</p>
</li>
<li>
<p>that can be used for instantiation (i.e. the represented class is not abstract).</p>
<div class="paragraph">
<p>So, same situation as before except that we know nothing about the constructor function’s signature.
However, if <code>{C}</code> has a covariant constructor, cf. <a href="classifiers.html#_covariant-constructors">Covariant Constructors</a>, we can still conclude that we have an override compatible
constructor function to that of <code>{C}</code>, because classes with covariant constructors enforce all their subclasses to have override compatible constructors.</p>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>have a value of type <code>type{? extends C}</code> or <code>type{C}</code> (the two types are equivalent), we know we have:</p>
<div class="ulist">
<ul>
<li>
<p>an object representing a type (often constructor functions are used for this, e.g. in the case of classes, but could also be a plain object, e.g. in the case of interfaces),</p>
</li>
<li>
<p>that represents type <code>{C}</code> or a subtype thereof,</p>
</li>
<li>
<p>that cannot be used for instantiation (e.g. could be the constructor function of an abstract class, the object representing an interface, etc.).</p>
</li>
</ul>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>Slightly simplified, we can say that in the first above case we can always use the value for creating an instance with <code>new</code>, in the second case only if the
referenced type has a covariant constructor, cf. <a href="classifiers.html#_covariant-constructors">Covariant Constructors</a>, and never in the third case.</p>
</div>
</div>
<div class="sect3">
<h4 id="_constructors-and-prototypes-in-ecmascript-2015"><a class="anchor" href="#_constructors-and-prototypes-in-ecmascript-2015"></a><a class="link" href="#_constructors-and-prototypes-in-ecmascript-2015">4.11.3. Constructors and Prototypes in ECMAScript 2015</a></h4>
<div class="paragraph">
<p><a href="#fig-constructors-and-prototypes">Constructors and prototypes for two classes A and B in ECMAScript 2015 (not N4JS!)</a> for two classes A and B in ECMAScript 2015 shows the constructors, prototypes, and the relations between them for the ECMAScript 2015
code shown in <a href="#ex-constructors-and-prototypes">Constructors and Prototypes</a>.</p>
</div>
<div id="ex-constructors-and-prototypes" class="exampleblock">
<div class="title">Example 24. Constructors and Prototypes</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-javascript" data-lang="javascript">class A {}
class B extends A {}

var b = new B();</code></pre>
</div>
</div>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title=""></i>
</td>
<td class="content">
<a href="#fig-constructors-and-prototypes">Constructors and prototypes for two classes A and B in ECMAScript 2015 (not N4JS!)</a> shows plain ECMAScript 2015 only.
Also note that <code>A</code> is defined without an <code>extends</code> clause, which is what ECMAScript 2015 calls a <em>base class</em> (as opposed to a <em>derived class</em>).
The constructor of a base class always has Function.prototype as its prototype.
If we had defined <code>A</code> as <code>class A extends Object {}</code> in the listing above, then the constructor of <code>A</code> would have Object’s constructor as its prototype
(depicted in as a dashed red arrow), which would make a more consistent overall picture.
</td>
</tr>
</table>
</div>
<div id="fig-constructors-and-prototypes" class="imageblock" style="text-align: center">
<div class="content">
<img src="chapters/04_types/fig/ctorsProtosInES6.svg" alt="ctorsProtosInES6">
</div>
<div class="title">Figure 5. Constructors and prototypes for two classes A and B in ECMAScript 2015 (not N4JS!)</div>
</div>
<div class="paragraph">
<p>Base classes in the above sense are not available in N4JS.
If an N4JS class does not provide an <code>extends</code> clause, it will implicitly inherit from built-in class <code>N4Object</code>,
if it provides an <code>extends</code> clause stating <code>Object</code> as its super type, then it corresponds to what is shown in <a href="#fig-constructors-and-prototypes">Constructors and prototypes for two classes A and B in ECMAScript 2015 (not N4JS!)</a> with the red dashed arrow.</p>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_this-type"><a class="anchor" href="#_this-type"></a><a class="link" href="#_this-type">4.12. This Type</a></h3>
<div class="paragraph">
<p>The <code>this</code> keyword may represent either a <code>this</code> literal (cf. <a href="#ex:this-keyword-and-type-in-instance-and-static-context">This keyword and type in instance and static context</a>) or may refer to the <code>this</code> type.
In this section, we describe the latter case.</p>
</div>
<div class="paragraph">
<p>Typical use cases of the <code>this</code> type include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>declaring the return type of instance methods</p>
</li>
<li>
<p>declaring the return type of static methods</p>
</li>
<li>
<p>as formal parameter type of constructors in conjunction with use-site structural typing</p>
</li>
<li>
<p>the parameter type of a function type expression, which appears as type of a method parameter</p>
</li>
<li>
<p>the parameter type in a return type expression (<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></math><code>{this}</code>,<code>constructor{this}</code>)</p>
</li>
<li>
<p>an existential type argument inside a return type expression for methods (e.g.<code>ArrayList&lt;? extends this&gt; method(){&#8230;&#8203;}</code>)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The precise rule where it may appear is given below in <a href="#Req-IDE-37">[Req-IDE-37]</a>.</p>
</div>
<div class="paragraph">
<p>The <code>this</code> type is similar to a type variable, and it is bound to the declared or inferred type of the receiver.
If it is used as return type, all return statements of the methods must return the <code>this</code> keyword or a variable value implicitly inferred to a <code>this</code> type (e.g. <code>var x = this; return x;</code>).</p>
</div>
<div class="listingblock">
<div class="title">Simple This Type</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {
    f(): this {
        return this;
    }
})
class B extends A {}

var a: A; var b: B;
a.f(); // returns something with the type of A
b.f(); // returns something with the type of B</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>this</code> can be thought of as a type variable which is implicitly substituted with the declaring class (i.e. this type used in a class <code>{A}</code> actually means <code>&lt;? extends A&gt;</code>).</p>
</div>
<div class="sect3">
<h4 id="this-type-syntax"><a class="anchor" href="#this-type-syntax"></a><a class="link" href="#this-type-syntax">4.12.1. Syntax</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">ThisTypeRef returns ThisTypeRef:
    ThisTypeRefNominal | ThisTypeRefStructural;

ThisTypeRefNominal returns ThisTypeRefNominal:
    {ThisTypeRefNominal} 'this'
;

ThisTypeRefStructural  returns ThisTypeRefStructural:
        typingStrategy=TypingStrategyUseSiteOperator
        'this'
        ('with' '{' ownedStructuralMembers+=TStructMember* '}')?
;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The keyword <code>this</code> and the type expression <code>this</code> look similar, however they can refer to different types.
The type always refers to the type of instances of a class.
The <code>this</code> keyword refers to the type of instances of the class in case of instance methods, but to the classifier the of the class in case of static methods.
See <a href="grammar.html#_this-keyword">This Keyword</a> for details.</p>
</div>
<div id="ex:this-keyword-and-type-in-instance-and-static-context" class="exampleblock">
<div class="title">Example 25. This keyword and type in instance and static context</div>
<div class="content">
<div class="paragraph">
<p>Note that the following code is not working, because some usages below are
not valid in N4JS. This is only to demonstrate the types.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class C {
    instanceMethod() {
        var c: this = this;
    }
    static staticMethod() {
        var C: type{this} = this;
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Structural typing and additional members in structural referenced types is described in <a href="classifiers.html#_structural-typing">Structural Typing</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="this-keyword-semantics"><a class="anchor" href="#this-keyword-semantics"></a><a class="link" href="#this-keyword-semantics">4.12.2. Semantics</a></h4>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-37"></a><strong>Req. IDE-37:</strong> <a href="#Req-IDE-37">This Type</a> (ver. 1)</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>this</code> used in the context of a class is actually inferred to an existential type <code>? extends A</code> inside the class itself.</p>
</li>
<li>
<p>the <code>this</code> type may only be used</p>
<div class="ulist">
<ul>
<li>
<p>as the type of a formal parameter of a constructor, if and only if combined with use-site structural typing.</p>
</li>
<li>
<p>at covariant positions within member declarations, except for static members of interfaces.</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="paragraph">
<p>Remarks</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Due to the function subtype relation and constraints on overriding methods (in which the overriding method has to be a subtype of the overridden method),
it is not possible to use the <code>this</code> type in formal parameters but only as return type. The following listing demonstrates that problem:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {
    bar(x: this): void { ... } // error
    // virtually defines: bar(x: A): void
}
class B extends A {
    // virtually defines: bar(x: B): void
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>As the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> type is replaced similar to a type variable, the virtually defined method <code>bar</code> in is not override compatible with <code>bar</code> in <code>A</code>.</p>
</div>
<div class="paragraph">
<p>In case of constructors, this problem does not occur because a subclass constructor does not need to be override compatible with the constructor of the super class.
Using <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> as the type of a constructor’s parameter, however, would mean that you can only create an instance of the class if you already have
an instance (considering that due to the lack of method overloading a class can have only a single constructor), making creation of the first instance impossible.
Therefore, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> is also disallowed as the type of a constructor’s parameter.</p>
</div>
</li>
<li>
<p>The difference between the type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> and the keyword <code>this</code> is when and how theactual type is set:
the actual type of the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> type is computed at compile(or validation) time and is always the containing type (of the member in which the type expression is used)
or a subtype of that type – this isnot a heuristic, this is so by definition.
In contrast, the actual typeof the keyword <code>this</code> is only available at runtime, while the type used at compilation time is only a heuristically-computed type, in other words,a good guess.</p>
</li>
<li>
<p>The value of the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> type is, in fact, not influenced by any <code>@This</code> annotations.
Instead of using <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> in these cases, the type expressions in the <code>@This</code> annotations can be used.</p>
</li>
<li>
<p>The <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> type is always bound to the instance-type regardless of the context it occurs in (non-static or static).
To refer to the this-classifier (static type) the construct <code>type{this}</code> is used.</p>
</li>
</ul>
</div>
<div style="page-break-after: always;"></div>
<div class="exampleblock">
<div class="title">Example 26. This type in function-type-expression</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {
    alive: boolean = true;
    methodA(func: {function(this)}): string {
       func(this);   // applying the passed-in function
       return "done";
    }
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The use of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>h</mi><mi>i</mi><mi>s</mi></math> type is limited to situations where it cannot be referred in mixed co- and contra-variant ways.
In the following example the problem is sketched up. <sup class="footnote">[<a id="_footnoteref_26" class="footnote" href="appendix_c_bibliography.html#_footnote_26" title="View footnote.">26</a>]</sup></p>
</div>
<div class="exampleblock">
<div class="title">Example 27. Problems with this type and type arguments</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">// Non-working example, see problem in line 15.
class M&lt;V&gt; {  public value: V;  }
class A {
    public store: M&lt;{function(this)}&gt;; // usually not allowed, but let's assume it would be possible----
}
class B extends A { public x=0; } // type of store is M&lt;{function(B)}&gt;

var funcA = function(a: A) {/*...something with a...*/}
var funcB = function(b: B) { console.log(b.x); }
var a: A = new A();  var b: B = new B();
b.store.value = funcA  // OK, since {function(A)} &lt;: {function(B)}
b.store.value = funcB  // OK.

var a2: A = b; // OK, since B is a subtype of A
a2.store.value( a ) // RUNTIME ERROR, the types are all correct, but remember b.store.value was assigned to funcB, which can only handle subtypes of B!</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_enums"><a class="anchor" href="#_enums"></a><a class="link" href="#_enums">4.13. Enums</a></h3>
<div class="paragraph">
<p>Enums are an ordered set of literals.
Although enums are not true classes, they come with built-in methods for accessing value, name and type name of the enum.</p>
</div>
<div class="paragraph">
<p>In N4JS, two flavours of enumerations are distinguished: ordinary enums (N4JS) and string based enums.
Ordinary enums (or in short, enums) are used while programming in N4JS.
String based enums are introduced to access enumerations derived from standards, mainly developed by the W3C, in order to access the closed set of string literals defined in webIDL syntax.</p>
</div>
<div class="sect3">
<h4 id="_enums-n4js"><a class="anchor" href="#_enums-n4js"></a><a class="link" href="#_enums-n4js">4.13.1. Enums (N4JS)</a></h4>
<div class="paragraph">
<p>Definition and usage of an enumeration:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">// assume this file to be contained in a package "myPackage"
enum Color {
    RED, GREEN, BLUE
}

enum Country {
    DE : "276",
    US : "840",
    TR : "792"
}

var red: Color = Color.RED;
var us: Country = Country.US;

console.log(red.name); // --&gt; RED
console.log(red.value); // --&gt; RED
console.log(red.n4class.fqn); // --&gt; myPackage.Color
console.log(red.toString()); // --&gt; RED

console.log(us.name); // --&gt; US
console.log(us.value); // --&gt; 840
console.log(us.n4classfqn); // --&gt; myPackage.Country
console.log(us.toString()); // --&gt; 840</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="enums-syntax"><a class="anchor" href="#enums-syntax"></a><a class="link" href="#enums-syntax">4.13.1.1. Syntax</a></h5>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">N4EnumDeclaration &lt;Yield&gt;:
	=&gt;(	{N4EnumDeclaration}
		(declaredModifiers+=N4Modifier)*
		'enum' name=BindingIdentifier&lt;Yield&gt;? )
	'{'
		(literals+=N4EnumLiteral (',' literals+=N4EnumLiteral)*)?
	'}';

N4EnumLiteral: name=IdentifierName (':' value=STRING)?;</code></pre>
</div>
</div>
</div>
<div class="sect4 language-n4js">
<h5 id="enums-semantics"><a class="anchor" href="#enums-semantics"></a><a class="link" href="#enums-semantics">4.13.1.2. Semantics</a></h5>
<div class="paragraph">
<p>The enum declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>E</mi></math> is of type <code>type{E}</code> and every enumeration is implicitly derived from <code>N4Enum</code>.
There are similarities to other languages such as Java, for example, where the literals of an enum are treated as final static fields with the type
of the enumeration and the concrete enumeration provides specific static methods including the literals.
This leads to the following typing rules:</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-38"></a><strong>Req. IDE-38:</strong> <a href="#Req-IDE-38">Enum Type Rules</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a given enumeration declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>E</mi></math> with literals <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>L</mi></math>, the following type rules are defined:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Every enumeration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>E</mi></math> is a subtype of the base type <code>N4Enum</code>:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mi>E</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>N</mi><mn>4</mn><mi>E</mi><mi>n</mi><mi>u</mi><mi>m</mi></mrow></mfrac><mrow/></math>
</div>
</div>
<div class="paragraph">
<p>which itself is a subtype of <code>Object</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>N</mi><mn>4</mn><mi>E</mi><mi>n</mi><mi>u</mi><mi>m</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>O</mi><mi>b</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p>Every literal <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>L</mi></math> of an enumeration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>E</mi></math> is
of the type of the enumeration:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>L</mi><mo>∈</mo><mi>E</mi><mo>.</mo><mi>l</mi><mi>i</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>a</mi><mi>l</mi><mi>s</mi></mrow><mrow><mi>Γ</mi><mo>⊢</mo><mi>L</mi><mi>:</mi><mi>E</mi></mrow></mfrac></math>
</div>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>This means that every literal is a subtype of <code>N4Enum</code> and <code>Object</code>:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>L</mi><mo>∈</mo><mi>E</mi><mo>.</mo><mi>l</mi><mi>i</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>a</mi><mi>l</mi><mi>s</mi></mrow><mrow><mi>L</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>N</mi><mn>4</mn><mi>E</mi><mi>n</mi><mi>u</mi><mi>m</mi><mo>∧</mo><mi>L</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>O</mi><mi>b</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>The base enumeration type <code>N4Enum</code> is defined as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">/**
 * Base class for all enumeration, literals are assumed to be static constant fields of concrete subclasses.
 */
public object N4Enum {

    /**
     * Returns the name of a concrete literal
     */
    public get name(): string

    /**
     * Returns the value of a concrete literal. If no value is
     * explicitly set, it is similar to the name.
     */
    public get value(): string

    /**
     * Returns a string representation of a concrete literal, it returns
     * the same result as value()
     */
     public toString(): string

    /**
     * Returns the meta class object of this enum literal for reflection.
     * The very same meta class object can be retrieved from the enumeration type directly.
     */
    public static get n4type(): N4EnumType

    //IDE-785 this as return type in static

    /**
     * Returns array of concrete enum literals
     */
    public static get literals(): Array&lt;? extends this&gt;

    /**
     * Returns concrete enum literal that matches provided name,
     * if no match found returns undefined.
     */
    public static findLiteralByName(name: string): this

    /**
     * Returns concrete enum literal that matches provided value,
     * if no match found returns undefined.
     */
    public static findLiteralByValue (value: string): this
}</code></pre>
</div>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-39"></a><strong>Req. IDE-39:</strong> <a href="#Req-IDE-39">Unique literal names</a> (ver. 1)</p>
</div>
<div class="ulist">
<ul>
<li>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo>∀</mo><mi>i</mi><mo>,</mo><mi>j</mi><mi>:</mi><mi>l</mi><mi>i</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>a</mi><mi>l</mi><mi>s</mi><mfenced close="]" open="["><mi>i</mi></mfenced><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo><mi>l</mi><mi>i</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>a</mi><mi>l</mi><mi>s</mi><mfenced close="]" open="["><mi>j</mi></mfenced><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>⇔</mo><mi>i</mi><mo>=</mo><mi>j</mi></math></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Literal names have to be unique.</p>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-40"></a><strong>Req. IDE-40:</strong> <a href="#Req-IDE-40">Enum Literals are Singletons</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>Enum literals are singletons:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>∀</mo><msub><mi>e</mi><mn>1</mn></msub><mo>,</mo><msub><mi>e</mi><mn>2</mn></msub><mo>,</mo><mi>μ</mi><mfenced close=")" open="("><msub><mi>e</mi><mn>1</mn></msub></mfenced><mo>=</mo><mi>μ</mi><mfenced close=")" open="("><msub><mi>e</mi><mn>2</mn></msub></mfenced><mo>=</mo><mstyle mathvariant="monospace"><mtext>N4EnumLiteral</mtext></mstyle><mo>∧</mo><mi>Γ</mi><mo>⊢</mo><msub><mi>e</mi><mn>1</mn></msub><mo>=</mo><mi>Γ</mi><mo>⊢</mo><msub><mi>e</mi><mn>2</mn></msub><mi>:</mi><msub><mi>e</mi><mn>1</mn></msub><mo>=</mo><mo>=</mo><msub><mi>e</mi><mn>2</mn></msub><mo>⇔</mo><msub><mi>e</mi><mn>1</mn></msub><mo>=</mo><mo>=</mo><mo>=</mo><msub><mi>e</mi><mn>2</mn></msub></math>
</div>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 28. Enumeration List</div>
<div class="content">
<div class="paragraph">
<p>Due to the common base type <code>N4Enum</code> it is possible to define generics accepting only enumeration, as shown in this example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">enum Color { R, G, B}

class EList&lt;T extends N4Enum&gt; {
    add(t: T) {}
    get(): T { return null; }
}

var colors: EList&lt;Color&gt;;
colors.add(Color.R);
var c: Color = colors.get();</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_string-based-enums"><a class="anchor" href="#_string-based-enums"></a><a class="link" href="#_string-based-enums">4.13.2. String-Based Enums</a></h4>
<div class="paragraph">
<p>In current web standards [<a href="appendix_c_bibliography.html#W3C:Steen:14:XL">W3C:Steen:14:XL</a>], definitions of enumerations are often given in webIDL syntax.
While the webIDL-definition assembles a set of unique string literals as a named enum-entity, the language binding to ECMAScript refers to the usage of the members of these enumerations only.
Hence, if an element of an enumeration is stored in a variable or field, passed as a parameter into a method or function or given back as a result, the actual type in JavaScript will be <code>string</code>.
To provide the N4JS user with some validations regarding the validity of a statement at compile time, a special kind of subtypes of <code>string</code> are introduced: the string-based enum using the <code>@StringBased</code> annotation.
(See also other string-based types like <code>typename&lt;T&gt;</code> <code>pathSelector&lt;T&gt;</code> and <code>i18nKey</code> in <a href="#_primitive-pathselector-and-i18nkey">Primitive Pathselector and I18nKey</a>.)</p>
</div>
<div class="paragraph">
<p>String-based enums do not have any kind of runtime representation; instead, the transpiler will replace each reference to a literal of a string-based enum by a corresponding string literal in the output code.
Furthermore, no meta-information is available for string-based enums, i.e. the <code>n4type</code> property is not available.
The only exception is the static getter <code>literals</code>: it is available also for string-based enums and has the same meaning.
In case of string-based enums, however, there won’t be a getter used at runtime; instead, the transpiler replaces every read access to this getter by an array literal containing a string literal for each of the enum’s literals.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-41"></a><strong>Req. IDE-41:</strong> <a href="#Req-IDE-41">String-Based Enum Type Rules</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>For a string-based enum declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mi>S</mi></msub></math> with literals <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>L</mi><mi>S</mi></msub></math> the following type rules are defined:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Every string-based enumeration <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mi>S</mi></msub></math> is a subtype of the base type <code>N4StringBasedEnum</code>:</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow/><mrow><mi>Γ</mi><mo>⊢</mo><mstyle mathvariant="monospace"><mtext>type</mtext></mstyle><mfenced close="}" open="{"><msub><mi>E</mi><mi>S</mi></msub></mfenced><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>N4StringBasedEnum</mtext></mstyle></mrow></mfrac><mrow/></math>
</div>
</div>
<div class="paragraph">
<p>which itself is not related to the standard enumeration type <code>N4Enum</code></p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>N4StringBasedEnum</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>N4Enum</mtext></mstyle></mrow></mfrac></mtd></mtr><mtr><mtd><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>N4Enum</mtext></mstyle><mspace width="1.0mm"/><mo>≮</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>N4StringBasedEnum</mtext></mstyle></mrow></mfrac></mtd></mtr></mtable></math>
</div>
</div>
</li>
<li>
<p><code>N4StringBasedEnum</code> is a subtype of <code>string</code></p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mfrac><mrow/><mrow><mstyle mathvariant="monospace"><mtext>N4StringBasedEnum</mtext></mstyle><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mstyle mathvariant="monospace"><mtext>string</mtext></mstyle></mrow></mfrac></mtd></mtr></mtable></math>
</div>
</div>
</li>
<li>
<p>Each literal in <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>L</mi><mi>S</mi></msub></math> of a string-based enumeration
<math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>E</mi><mi>S</mi></msub></math> is of the type of the string-based enumeration.</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>l</mi><mo>∈</mo><msub><mi>E</mi><mi>S</mi></msub><mo>.</mo><msub><mi>L</mi><mi>S</mi></msub></mrow><mrow><mi>Γ</mi><mo>⊢</mo><mi>l</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><msub><mi>E</mi><mi>S</mi></msub></mrow></mfrac></math>
</div>
</div>
</li>
<li>
<p><a href="#Req-IDE-39">[Req-IDE-39]</a> also applies for <code>N4StringBasedEnum</code>.</p>
</li>
<li>
<p><a href="#Req-IDE-40">[Req-IDE-40]</a> also applies for <code>N4StringBasedEnum</code>.</p>
</li>
<li>
<p>References to string-based enums may only be used in the following places:</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>in type annotations</p>
</li>
<li>
<p>in property access expressions to refer to one of the enum’s literals</p>
</li>
<li>
<p>in property access expressions to read from the static getter <code>literals</code></p>
<div class="paragraph">
<p>In particular, it is invalid to use the type of a string-based enum as a
value, as in</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">    @StringBased enum Color { RED, GREEN, BLUE }
    var c = Color;</code></pre>
</div>
</div>
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="exampleblock">
<div class="title">Example 29. WebIDL example</div>
<div class="content">
<div class="listingblock">
<div class="title">Gecko-Engine webIDL XMLHttpRequestResponseType as taken from [<a href="appendix_c_bibliography.html#W3C:Steen:14:XL">W3C:Steen:14:XL</a>]</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">enum XMLHttpRequestResponseType {
  "",
  "arraybuffer",
  "blob",
  "document",
  "json",
  "text" //, ... and some mozilla-specific additions
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Compatible Definition of this Enumeration in N4JS, provided through a
runtime-library definition:</p>
</div>
<div class="listingblock">
<div class="title">File in source-folder: w3c/dom/XMLHttpRequestResponseType.n4js</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">@StringBased enum XMLHttpRequestResponseType {
  vacant : "",
  arrayBuffer : "arraybuffer",
  blob : "blob",
  document : "document",
  json : "json",
  text : "text"
 }</code></pre>
</div>
</div>
<div class="paragraph">
<p>Usage of the enumeration in the definition files of the runtime-library.
Note the explicit import of the enumeration.</p>
</div>
<div class="listingblock">
<div class="title">XMLHttpRequestResponse.n4jsd</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">@@ProvidedByRuntime
import XMLHttpRequestResponseType from "w3c/dom/XMLHttpRequestResponseType";
@Global
export external public class XMLHttpRequestResponse extends XMLHttpRequestEventTarget {
  // ...
  // Setter Throws TypeError Exception
  public responseType: XMLHttpRequestResponseType;
  // ...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Client code importing the runtime-library as defined above can now use the Enumeration in a type-safe way:</p>
</div>
<div class="listingblock">
<div class="title">String-Based Enumeration Usage</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import XMLHttpRequestResponseType from "w3c/dom/XMLHttpRequestResponseType";

public function process(req: XMLHttpRequest) : void {
  if( req.responseType == XMLHttpRequestResponseType.text ) {
    // do stuff ...
  } else {
       // signal unrecognized type.
       var errMessage: req.responseType + " is not supported"; // concatination of two strings.
       show( errMessage );
  }
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_short-hand-syntax"><a class="anchor" href="#_short-hand-syntax"></a><a class="link" href="#_short-hand-syntax">4.14. Short-Hand Syntax</a></h3>
<div class="paragraph">
<p>Short-hand syntax is available for a number of built-in types.</p>
</div>
<div class="sect3">
<h4 id="_array-short-hand-syntax"><a class="anchor" href="#_array-short-hand-syntax"></a><a class="link" href="#_array-short-hand-syntax">4.14.1. Array Short-Hand Syntax</a></h4>
<div class="paragraph">
<p>For the built-in type <code>Array</code> a convenience short form is available. Thus, writing</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let arr: string[];</code></pre>
</div>
</div>
<div class="paragraph">
<p>is equivalent to</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let arr: Array&lt;string&gt;;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Multi-dimensional arrays can be declared as such:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let arr: string[][][];</code></pre>
</div>
</div>
<div class="paragraph">
<p>which is equivalent to</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let arr: Array&lt;Array&lt;Array&lt;string&gt;&gt;&gt;;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_iterablen-short-hand-syntax"><a class="anchor" href="#_iterablen-short-hand-syntax"></a><a class="link" href="#_iterablen-short-hand-syntax">4.14.2. IterableN Short-Hand Syntax</a></h4>
<div class="paragraph">
<p>The built-in IterableN types (i.e. <code>Iterable2</code>, <code>Iterable3</code>, &#8230;&#8203; <code>Iterable9</code>, see <a href="#IterableN">IterableN</a>) are
also provided with a short-hand syntax. For example, writing</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let i3: [string,number,string[]];</code></pre>
</div>
</div>
<div class="paragraph">
<p>would be equivalent to</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let i3: Iterable3&lt;string,number,Array&lt;string&gt;&gt;;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note the following special cases:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let i0: [];
let i1: [string];
let union: string|number[];</code></pre>
</div>
</div>
<div class="paragraph">
<p>which is equivalent to</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">let i0: Iterable&lt;?&gt;;
let i1: Iterable&lt;string&gt;;
let union: union{string,Array&lt;number&gt;}; // not: Array&lt;union{string,number}&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Further note: while this syntax is very similar to TypeScript&#8217;s tuple syntax, the semantics
of tuples and IterableN are very different.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 0.9<br>
Last updated 2019-08-08 13:15:33 CEST
</div>
</div>
<!-- ************* docinfo-footer *************************************************************** -->
<div class="Grid social" style="color:#d5dfea">
  <div class="Cell Cell--2-12 m-Cell--withMargin">
    <h2>Quick Links</h2>
    <ul>
      <li><a href="../downloads.html">Download</a></li>
      <li><a href="../userguides/index.html">Documentation</a></li>
      <li><a href="https://github.com/eclipse/n4js/">Source</a></li>
      <li><a href="https://github.com/eclipse/n4js/issues">Issues</a></li>
    </ul>
  </div>
  <div class="Cell Cell--2-12 m-Cell--withMargin">
    <br/><br/>
    <ul>
      <li><a href="https://www.eclipse.org/forums/index.php/f/365/">Forum</a></li>
      <li><a href="http://n4js.blogspot.de/">Blog</a></li>
      <li><a href="https://dev.eclipse.org/mailman/listinfo/n4js-dev">Mailing List</a></li>
      <li><a href="https://projects.eclipse.org/projects/technology.n4js">Eclipse Project Page</a></li>
      <li><a href="https://twitter.com/n4jsdev">Tweets by n4jsdev</a></li>
    </ul>
  </div>
  <div class="Cell Cell--2-12 m-Cell--withMargin">
    <br/><br/>
    <ul>
      <li><a href="http://www.eclipse.org/">Eclipse Home</a></li>
      <li><a href="http://www.eclipse.org/legal/privacy.php">Privacy Policy</a></li>
      <li><a href="http://www.eclipse.org/legal/termsofuse.php">Terms of Use</a></li>
      <li><a href="http://www.eclipse.org/legal/copyright.php">Copyright Agent</a></li>
      <li><a href="http://www.eclipse.org/legal/">Legal</a></li>
    </ul>
  </div>
  <div style="clear: both; height: 0; overflow: hidden;"></div>
</div>

<!-- ************* UI Scripts ************* -->
<script type="text/javascript" src="scripts/back-to-top.js"></script>

<script type="text/javascript" src="scripts/treeview.js"></script>
<script type="text/javascript" src="scripts/toc.js"></script>

<!-- ************* Prism.js Syntax Highlighting ************* -->
<script src="scripts/prism.js"></script>

<script type="text/javascript">
	// Add the 'toclist' id for search function
	$(".toc2 > ul").attr('id', 'toclist');
	// Generate a Search input form
	$("#toclist > li:first-of-type").before('<input type="text" id="pagesearch" onkeyup="search()" placeholder="Search for section...">');
	$("#toclist > li:first-of-type").before('<i id="clear" class="fa fa-times-circle-o"></i>');
	$("#clear").click(function(){
	    $("#pagesearch").val('');
	    search();
	    $('.toc2 > ul').treeView('collapseAll');
	});
	// intialize Treeview.js
	$(".toc2 > ul").treeView();
	// Initialize Scrollspy
</script>
<!-- ************* docinfo-footer *************************************************************** -->
</body>
</html>